Ultra Fast Text to Speech (WAV -> MP3) in ASP.NET MVC

后端 未结 2 1778
小鲜肉
小鲜肉 2021-02-06 16:16

This question is essentially about the suitability of Microsoft\'s Speech API (SAPI) for server workloads and whether it can be used reliably inside of w3wp for

2条回答
  •  不要未来只要你来
    2021-02-06 17:10

    This question is a bit old now, but this is what I'm doing and it's been working great so far:

        public Task Speak(string text)
        {
            return Task.Factory.StartNew(() =>
            {
                using (var synthesizer = new SpeechSynthesizer())
                {
                    var ms = new MemoryStream();
                    synthesizer.SetOutputToWaveStream(ms);
                    synthesizer.Speak(text);
    
                    ms.Position = 0;
                    return new FileStreamResult(ms, "audio/wav");
                }
            });
        }
    

    might help someone...

提交回复
热议问题