
This synthesizes to the current active output device. To do this, omit the AudioConfig parameter when creating the SpeechSynthesizer in the example above. In some cases, you may want to directly output synthesized speech directly to a speaker. This is a good example of the most basic usage, but next you look at customizing output and handling the output response as an in-memory stream for working with custom scenarios. wav file is written to the location you specified. Using var synthesizer = new SpeechSynthesizer(config, audioConfig) Īwait synthesizer.SpeakTextAsync("A simple test to write to a file.") Then, executing speech synthesis and writing to a file is as simple as running SpeakTextAsync() with a string of text. Pass your config object and the audioConfig object as params. Next, instantiate a SpeechSynthesizer with another using statement. Using var audioConfig = AudioConfig.FromWavFileOutput("path/to/write/file.wav") A using statement in this context automatically disposes of unmanaged resources and causes the object to go out of scope after disposal. wav file, using the FromWavFileOutput() function, and instantiate it with a using statement. To start, create an AudioConfig to automatically write the output to a. The SpeechSynthesizer accepts as params the SpeechConfig object created in the previous step, and an AudioConfig object that specifies how output results should be handled. Next, you create a SpeechSynthesizer object, which executes text-to-speech conversions and outputs to speakers, files, or other output streams. Var config = SpeechConfig.FromSubscription("", "")
#Convert text to wav code#
You also create some basic boilerplate code to use for the rest of this article, which you modify for different customizations. Get these credentials by following steps in Try the Speech service for free. In this example, you create a SpeechConfig using a speech key and location/region.
#Convert text to wav install#
Install the Speech SDKīefore you can do anything, you'll need to install the Speech SDK. If you don't have an account and subscription, try the Speech service for free. This article assumes that you have an Azure account and Speech service subscription. If you want to skip straight to sample code, see the C# quickstart samples on GitHub.
