2016-04-04 19 views
0

語音合成無法SetVoice()。所有被列爲啓用,直到它被嘗試,然後失敗與非默認列爲'禁用'。SpeechSynthesis無法在ASP.NET下使用SelectVoice?

注意:這適用於WPF或控制檯應用程序,但作爲ASP.NET應用程序失敗。 ALSO:由於它會永久鎖定ASP.NET應用程序的主線程,因此會在另一個線程(Task.Run(()=> StartSpeech())上創建語音(詳情請參閱No response to a HTTP Get request in WebAPI in .NET 4.5 while using SpeechSynthesis for converting text to speech)。但是,SelectVoice兩個備用線以及主要的。

想法?

 private SpeechSynthesizer speech; //System.Speech.Synthesis 
     var voices = speech.GetInstalledVoices(); 
     //[0]: "Microsoft David Desktop" ["Enabled"] 
     //[1]: "IVONA 2 Emma" ["Enabled"] 
     //[2]: "Microsoft Zira Desktop" ["Enabled"] 

     try 
     { 
      speech.SelectVoice("Microsoft Zira Desktop"); 
     } 
     catch (Exception e) 
     { 
      var p = e; //fails (System.ArgumentException: Cannot set voice. No matching voice is installed or the voice was disabled) 
     } 

     voices = speech.GetInstalledVoices(); 
     //[0]: "Microsoft David Desktop" ["Disabled"] 
     //[1]: "IVONA 2 Emma" ["Enabled"] 
     //[2]: "Microsoft Zira Desktop" ["Disabled"] 

     speech.SpeakAsync(text); 
+1

嗨吉姆,它是否在你的本地機器或生產失敗? – Thomas

+0

wpf/console應用程序正常工作的本地機器。 – Jim

+0

托馬斯 - 你讓我思考權利/過程...新的信息:它只在IIS下失敗。本地運行(VS-f5-iis-express) - 工作正常。奇。 – Jim

回答

0

事實證明,這甚至在Visual Studio的IIS快遞的工作,但在IIS下失敗了。從ApplicationPoolIdentity切換到本地系統使工作。似乎像SelectVoice()是一個啓用權限的調用,其簡單地說不是。

An swer:將應用程序池的標識(在IIS中)更改爲LocalSystem。