- Xamarin Blueprints
- Michael Williams
- 232字
- 2021-07-08 11:48:24
WinPhone text-to-speech implementation
Now we go back to Windows Phone for the last implementation. See how tricky it can be when you have to switch between multiple platforms. Imagine if we had to change languages and re-write IoC containers; the amount of work would be much greater. Not only that, there would be no point in using IoC, because we cannot share any code.
So firstly, don't forget to import the nuget package for Autofac:

Now that we have access to the Autofac framework, let's continue implementing the text to speech service. Start with adding a new folder called Services, then add the TextToSpeechWinPhone.cs
file and implement it:
public class TextToSpeechWinPhone : ITextToSpeech { public async void Speak(string text) { MediaElement mediaElement = new MediaElement (); var synth = new Windows.Media.SpeechSynthesis. SpeechSynthesizer (); SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text); mediaElement.SetSource(stream, stream.ContentType); mediaElement.Play(); } }
Looking at this more closely, you can see the instantiation of MediaElement
; this is used to play an audio source. Our source in this case is SpeechSynthesisStream
; this stream is built via a speech synthesizer. When we call the function SynthesizeTextToStreamAsync
, it will be an audio stream based on the text inserted into this function. We then set the MediaElement
source to the stream and call the Play
function to begin speaking. One addition to configuring Windows Phone is checking the capability in the app manifest file.
- The Complete Rust Programming Reference Guide
- Unreal Engine Physics Essentials
- 玩轉(zhuǎn)Scratch少兒趣味編程
- LabVIEW Graphical Programming Cookbook
- Building Modern Web Applications Using Angular
- PyTorch自然語(yǔ)言處理入門(mén)與實(shí)戰(zhàn)
- Android 9 Development Cookbook(Third Edition)
- RTC程序設(shè)計(jì):實(shí)時(shí)音視頻權(quán)威指南
- C++程序設(shè)計(jì)基礎(chǔ)教程
- 嚴(yán)密系統(tǒng)設(shè)計(jì):方法、趨勢(shì)與挑戰(zhàn)
- Drupal 8 Module Development
- Gradle for Android
- JavaScript程序設(shè)計(jì):基礎(chǔ)·PHP·XML
- 跟戴銘學(xué)iOS編程:理順核心知識(shí)點(diǎn)
- Appcelerator Titanium:Patterns and Best Practices