2016-03-13 31 views
2

我有我的本地服務器上運行下面的非常基本的TTS代碼調用SpeechAPI文本到語音在Azure上

using System.Speech.Synthesis; 
... 
SpeechSynthesizer reader = new SpeechSynthesizer(); 
reader.Speak("This is a test"); 

該代碼具有用於我在VS添加引用上System.Speech的依賴2015年項目。 工作正常,但從我已閱讀和嘗試它我知道這將無法工作時,代碼託管在Azure上。 我已經閱讀了幾篇有關SO查詢的帖子,如果它實際上可以在Azure上進行TTS。當然2年前它似乎不可能。 How to get System.Speech on windows azure websites?

所有的道路似乎導致的Microsoft Speech API https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/ 我已經註冊了,並已經得到了我的私人和SEC鍵調用這個API。 但是我的問題是這樣的。我如何實際調用SpeechAPI?在上面的簡單代碼示例中,我需要更改哪些內容,以便在Azure上運行時可以工作?

回答

1

你在Azure的市場稱爲語音API是一個名爲ProjectOxford的AI微軟項目,提供了計算機視覺,語音和語言的API陣列的一部分。

這些都是RESTful API中,這意味着你將構建HTTP請求發送給在雲中託管的在線服務。 語音到文本文檔可here,你可以找到示例代碼在github各種客戶端。特別是對於C#,您可以在this sample project中看到一些代碼。

請注意,ProjectOxford仍處於預覽版(測試版)。使用這些API的額外支持可以在ProjectOxford MSDN forum上找到。

但只是給你的你的程序將如何看起來像一個想法(從上面的示例代碼在GitHub上獲取):

 AccessTokenInfo token; 

     // Note: Sign up at http://www.projectoxford.ai for the client credentials. 
     Authentication auth = new Authentication("Your ClientId goes here", "Your Client Secret goes here"); 

     ... 

     token = auth.GetAccessToken(); 

     ... 

     string requestUri = "https://speech.platform.bing.com/synthesize"; 

     var cortana = new Synthesize(new Synthesize.InputOptions() 
     { 
      RequestUri = new Uri(requestUri), 
      // Text to be spoken. 
      Text = "Hi, how are you doing?", 
      VoiceType = Gender.Female, 
      // Refer to the documentation for complete list of supported locales. 
      Locale = "en-US", 
      // You can also customize the output voice. Refer to the documentation to view the different 
      // voices that the TTS service can output. 
      VoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)", 
      // Service can return audio in different output format. 
      OutputFormat = AudioOutputFormat.Riff16Khz16BitMonoPcm, 
      AuthorizationToken = "Bearer " + token.access_token, 
     }); 

     cortana.OnAudioAvailable += PlayAudio; 
     cortana.OnError += ErrorHandler; 
     cortana.Speak(CancellationToken.None).Wait(); 
+0

謝謝你,我不知道它是仍處於測試階段。看了在Azure網站上的定價,將花費我們幾乎$ 1mil的語音請求,我們目前處理的數量(250英里每年,成本我們在AWS EC2實例約50K,提供相同的服務),所以我試圖驗證是否我已經正確地閱讀了定價信息,3個不同的人發了3封電子郵件,我發現自己回到了他們的蔚藍價格頁面,對不起,「我們不確定」。看起來Azure不會爲我們的特定使用情況飛行:( – MayoMan

+0

您指的是哪個定價網站? ProjectOxford的定價可以在這裏找到:https://www.projectoxford.ai/pricing –

+0

請注意,由於它是在預覽,價格如有變動,這些API無論如何,如果你正在使用其他的方法來處理這些對EC2實例,並考慮遷移到Azure的,它的價值比較Azure的虛擬機的定價,以及在這裏:https://開頭蔚藍。 microsoft.com/en-us/pricing/calculator/這將是一個更「蘋果」比較「蘋果」的比較 –