如何将.wav音频文件转换为文本,并确定使用LUIS
问题描述:
我工作的机器人技术的意图,在我目前的项目我实现了Skype的呼叫功能中,我没有记录我的声音,并存储到Azure存储BLOB,但我想要如何将音频文件转换为文本的功能,然后使用LUIS识别该文本中的意图。如何将.wav音频文件转换为文本,并确定使用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
答
你应该看看Microsoft Cognitive Services Bing Speech API因为它没有你在找什么;将音频转换为文本。
这里有一个sample使用API。如果你发送一个WAV文件到机器人;它会根据API从音频中理解的内容做出回应。