java将音频流转换为PCM
我试图从文本到语音接口(MaryTTS)获取音频流,并在SIP RTP会话(使用对等方)中进行流式传输
对等方需要一个SoundSource
来流式传输音频,这是一个定义为
public interface SoundSource {
byte[] readData();
}
MaryTTS将String
合成为AudioInputStream
。我试图简单地读取流,并将其缓冲到实现SoundSource
的对等方,如
MaryInterface tts = new LocalMaryInterface();
AudioInputStream audio = tts.generateAudio("This is a test.");
SoundSource soundSource = new SoundSource() {
@Override
public byte[] readData() {
try {
byte[] buffer = new byte[1024];
audio.read(buffer);
return buffer;
} catch (IOException e) {
return null;
}
}
};
// issue call with soundSource using Peers
电话响了,我听到的是缓慢、低沉、嘈杂的声音,而不是合成语音。我猜这可能与SIP RTP会话所期望的音频格式有关,因为对等文档中指出
The sound source must be raw audio with the following format: linear PCM 8kHz, 16 bits signed, mono-channel, little endian.
如何转换/读取AudioInputStream
以满足这些要求
# 1 楼答案
我知道的一个方法是——考虑到您使用的系统,我不知道它是否会通过:
还有这个
可与上述参数一起使用