2011-09-06 41 views
0

我正在嘗試讓我的Windows應用程序讀取文本。我正在使用BingTranslationService來做到這一點,但我不確定如何從我從服務中獲得的結果播放音頻。我嘗試過使用SoundEffect類,但我不太清楚如何去做。如何從BingTranslationService返回的uri播放Windows手機中的音頻?

BingTranslateServiceReference.LanguageServiceClient client = new BingTranslateServiceReference.LanguageServiceClient(); 
    client.SpeakAsync(appID, name, "en", "audio/wav"); 

void client_OnSpeakCompleted(object sender, BingTranslateServiceReference.SpeakCompletedEventArgs e) 
{ 
    SoundEffect se; 
    SoundEffectInstance soundEffectInstance; 
    var req = (HttpWebRequest)WebRequest.Create(e.Result); 
    req.BeginGetRequestStream(new AsyncCallback(ReqCB), req); 
} 

回答

0

您可以使用的MediaElement或使用SoundEffect中玩這個

有一個很好的博客文章和完整的應用程序,使用MediaElement http://sigurdsnorteland.wordpress.com/2010/11/20/loud-tweets-a-twitter-to-speak-wp7-app-source-code-included/ - 也在codeplex

我已經在Iron7(和一些其他應用程序)中使用SoundEffect - 請參閱中的一些示例代碼和https://github.com/slodge/main/blob/master/Hosts/Silverlight/Iron7/Common/AudioPlayer.cs - 基本代碼:

var soundEffect = Microsoft.Xna.Framework.Audio.SoundEffect.FromStream(stream) 
FrameworkDispatcher.Update(); 
soundEffect.Play(); 

對於這些短的聲音片段(最多100個字符來,必應語音業務),我建議SoundEffect中的路線 - 它比MediaElement的打火機。