locked
How to Save SpeechSynthesis Audio to mp3 in a windows store app

    Question

  • I would Like to Save Speech Synthesis Audio to mp3 file.


    Rogelio Rios

    Friday, November 21, 2014 7:36 PM

Answers

  • The SpeechSynthesis object will generate a SpeechSynthesisStream with the audio in wav format. You can save this to a file like you'd save any other stream:

                var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
    
                SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");
    
                using (var reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);
                    IBuffer buffer = reader.ReadBuffer((uint)stream.Size);
                    await FileIO.WriteBufferAsync(outputFile, buffer);
                }
    

    If you specifically want mp3 you can use the Windows.Media.Transcoding API to transcode it to mp3. See see Quickstart: transcoding and Transcoding media sample (the samples do video, but the same techniques work on audio if you choose an audio profile.

    • Marked as answer by Roger Rios Jr Sunday, November 23, 2014 7:35 AM
    Saturday, November 22, 2014 2:11 AM
    Owner