2016-12-17 68 views
0

我工作的機器人技術的意圖,在我目前的項目我實現了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

回答

1

你應該看看Microsoft Cognitive Services Bing Speech API因爲它沒有你在找什麼;將音頻轉換爲文本。

這裏有一個sample使用API​​。如果你發送一個WAV文件到機器人;它會根據API從音頻中理解的內容做出迴應。

相關問題