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

Posted

技术标签:

【中文标题】如何将 .wav 音频文件转换为文本并使用 LUIS 识别意图【英文标题】:How to convert the .wav audio files into text and identify the intents using LUIS 【发布时间】:2016-12-17 09:04:15 【问题描述】:

我正在使用机器人技术,在我当前的项目中,我实现了 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 获得响应吗?

-Pradeep

【问题讨论】:

【参考方案1】:

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

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

【讨论】:

以上是关于如何将 .wav 音频文件转换为文本并使用 LUIS 识别意图的主要内容,如果未能解决你的问题,请参考以下文章

matlab将txt格式转成wav格式

如何使用 Nodejs 将 wav 文件转换为 8000hz

如何将音频数据数组转换为 wav 文件?

如何将 wav 音频文件格式(样本宽度)转换为 8 位格式?

如何将wav音频文件格式为pcm转化为ima adpcm格式

使用 NAudio 将 g722 音频转换为 WAV