.NET 3.0 文本转语音 WAV 输出太大且过程缓慢
我编写了一个小应用程序,它接收一些文本并将其转换为音频 wav。 现在,除了生成的 wav 文件太大之外,它工作正常。
我正在寻找使 wav 输出更小并使整个过程花费更少时间的方法。
示例代码:
public byte[] ConvertText2Wav(string text)
{
MemoryStream wavAudioStream = new MemoryStream();
SpeechSynthesizer speechEngine = new SpeechSynthesizer();
speechEngine.SetOutputToWaveStream(wavAudioStream);
speechEngine.Speak(text);
wavAudioStream.Flush();
Byte[] wavBytes = wavAudioStream.GetBuffer();
return wavBytes;
}
I wrote a little application that takes in some text and converts it to an audio wav.
now, it works fine except that the wav file produced is too big.
I'm looking on ways to make the wav output smaller and make the whole process take less time.
Sample Code :
public byte[] ConvertText2Wav(string text)
{
MemoryStream wavAudioStream = new MemoryStream();
SpeechSynthesizer speechEngine = new SpeechSynthesizer();
speechEngine.SetOutputToWaveStream(wavAudioStream);
speechEngine.Speak(text);
wavAudioStream.Flush();
Byte[] wavBytes = wavAudioStream.GetBuffer();
return wavBytes;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.wav 输出未压缩。
如果您想要“更小的”输出,请使用适当的编解码器并对其进行压缩。
.wav output is uncompressed.
If you want "smaller" output, use an appropriate codec and compress it.
您可以使用 LAME MP3 编码器将 WAV 输出转换为 MP3。正如 Anon 所说,这将导致输出文件更小。
http://lame.sourceforge.net/
You can use the LAME MP3 encoder to convert the WAV output to MP3. This will result in a smaller output file like Anon says.
http://lame.sourceforge.net/
您应该使用专门为语音构建的压缩编解码器,以获得最大可能的好处。 Speex 是免费且优秀的。您可以像这样在 C# 中使用它: http://www.codeproject.com/KB /cs/speexincsharp.aspx。
这将产生比通用或音乐编解码器更好的结果。
You should use a compression codec that is built specifically for speech to get the greatest possible benefit. Speex is free and excellent. You can use it from c# like this: http://www.codeproject.com/KB/cs/speexincsharp.aspx.
That will yield better results than a general purpose or music codec would.
波形文件本身很长。例如,您应该将其通过编解码器传递为电影的 XVID 或音频的 MP3 或 OGG。
查看本教程,了解如何使用 DirectShow
Wave files are long per se. You should pass it through a codec as XVID for movies or MP3 or OGG for audio for example.
Take a look at this tutorial on how to use DirectShow