如何将 .wav 音频文件转换为文本并使用 LUIS 识别意图

How to convert the .wav audio files into text and identify the intents using LUIS

我正在研究机器人技术,在我当前的项目中,我实现了 Skype 通话功能,因为我确实录制了我的声音并存储到 azure 存储 blob 中,但我想要将音频文件转换为文本然后识别的功能该文本中使用 LUIS 的意图。

这是我写的将录制内容上传到Azure存储的代码。

   private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
    {

        if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
        {
            var record = await recordOutcomeEvent.RecordedContent;
            string path = HttpContext.Current.Server.MapPath($"~/{recordOutcomeEvent.RecordOutcome.Id}.wav");//Wma,wav,Mp3  ~/
            using (var writer = new FileStream(path, FileMode.Create))
            {
                await record.CopyToAsync(writer);
            }
            try
            {

                var storageConnectionString = ConfigurationManager.AppSettings["RealtimeAnamoly_StorageConnectionString"];

                Debug.WriteLine(storageConnectionString);

                var storageAccount = CloudStorageAccount.Parse(storageConnectionString);

                // We are going to use Blob Storage, so we need a blob client.
                var blobClient = storageAccount.CreateCloudBlobClient();

                // Data in blobs are organized in containers.
                // Here, we create a new, empty container.
                CloudBlobContainer blobContainer = blobClient.GetContainerReference("myfirstcontainer");
                blobContainer.CreateIfNotExists();

                // Retrieve reference to a blob named "myblob".
                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference($"{recordOutcomeEvent.RecordOutcome.Id}.wav");

                // We also set the permissions to "Public", so anyone will be able to access the file.
                // By default, containers are created with private permissions only.
                blobContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

                // Create or overwrite the "myblob" blob with contents from a local file.
                using (var fileStream = System.IO.File.OpenRead(path))//@"path\myfile"
                {
                    blockBlob.UploadFromStream(fileStream);
                }

                //UploadAudioFiletoLuis(path);

                recordOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                {
                    GetSilencePrompt(),
                    GetPromptForText("Successfully Recorded your message! Please wait for Response")

                    //CreateIvrOptions(AthenaIVROptions.ALS,1,true)

                };

            }
            catch (Exception ex)
            {

            }
        }
        else
        {
            if (silenceTimes > 1)
            {
                recordOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                {
                    GetPromptForText("Thank you for calling"),
                    new Hangup() { OperationId = Guid.NewGuid().ToString() }
                };
                recordOutcomeEvent.ResultingWorkflow.Links = null;
                silenceTimes = 0;
            }
            else
            {
                silenceTimes++;
                recordOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                {
                    GetRecordForText("I didn't catch that, would you kinly repeat?")
                };
            }
        }
    }

能否请您介绍如何将 .wav 音频文件转换为文本,然后如何识别意图并从 LUIS 获取响应?

-普拉迪普

您应该查看 Microsoft Cognitive Services Bing Speech API,因为它可以满足您的需求;将音频转换为文本。

这里有一个sample使用了API。如果您向机器人发送 WAV 文件;它会根据 API 从音频中理解的内容进行响应。