简体   繁体   English

C#中的SpeechSynthesizer创建了22kHz的wav ...需要16kHz

[英]SpeechSynthesizer in C# creates wav that has 22kHz… needs to be 16kHz

My C# application needs to covert text to wav file and inject it into a Skype call. 我的C#应用​​程序需要将文本转换为wav文件并将其注入Skype调用。 The code that creates the wav file is below. 创建wav文件的代码如下所示。 The problem is that the file has 22kHz sample rate and Skype accepts only 16kHz. 问题是文件的采样率为22kHz,Skype只接受16kHz。

Is there any way to adjust this setting? 有没有办法调整此设置?

using (System.IO.FileStream stream = System.IO.File.Create("message.wav"))
{

System.Speech.Synthesis.SpeechSynthesizer speechEngine = new System.Speech.Synthesis.SpeechSynthesizer();

 speechEngine.SetOutputToWaveStream(stream);
 speechEngine.Speak(number);
 stream.Flush();
}

SetOutputToWaveFile() has an overload that accepts a SpeechAudioFormatInfo parameter, which can be used to set the sample rate. SetOutputToWaveFile()有一个接受SpeechAudioFormatInfo参数的重载,该参数可用于设置采样率。 Don't see one for SetOutputToWaveStream() , oddly, but since you're writing to a file anyway, that should work. 奇怪的是,没有为 SetOutputToWaveStream()看到一个,但是 因为你无论如何都要写一个文件,这应该有效。

Edit: 编辑:

As @Hans points out, the correct overload is SetOutputToAudioStream() to write to a stream. 正如@Hans指出的那样,正确的重载是SetOutputToAudioStream()来写入流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 NAudio 更改 wav 文件(到 16KHz 和 8bit) - change wav file ( to 16KHz and 8bit ) with using NAudio 我想将wav文件16 kHz 16位更改为8 kHz 16位单声道C#NAudio - I want change wav file 16 kHz 16 bit to 8 kHz 16 bit mono C# NAudio 为什么CSCore均衡器SampleFilters [9](16Khz)在C#中完全不受影响 - why CSCore equalizer SampleFilters[9] (16Khz) does not affect at all in C# 使用MediaComposition将音频从立体声.mp4文件转换为单WAV 16KHz - Transcode audio from stereo .mp4 file into mono WAV 16KHz using MediaComposition 使用NAudio将wav文件转换PCM 48kHz / 16比特率到u-law 8kHz / 8比特率 - wav file conversion PCM 48kHz/16 bit rate to u-law 8kHz/8 bit rate using NAudio C#SpeechSynthesizer使服务无响应 - C# SpeechSynthesizer makes service unresponsive C#SpeechSynthesizer —“系统上未安装语音” - C# SpeechSynthesizer - “No voice installed on the system” 在SpeechSynthesizer讲C#时调整文本大小 - Resizing Text while SpeechSynthesizer is speaking C# 如何使用SpeechSynthesizer C#将音频流写出到响应 - How to write audio stream out to response using SpeechSynthesizer C# 阅读 SpeechSynthesizer C# 时如何忽略特定字符? - How to ignore specific char while reading SpeechSynthesizer C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM