我正在尝试播放 Amazon Polly 返回的二进制字符串格式的音频文件。为此,我正在使用“react-native-fetch-blob”并读取流,但只是不断从网桥收到错误消息“无效的数据消息 - 都必须是长度:8”。当我尝试打开流时会发生这种情况:ifstream.open()
这是代码:
//polly config
const params = {
LexiconNames: [],
OutputFormat: "mp3",
SampleRate: "8000",
Text: "All Gaul is divided into three parts",
TextType: "text",
VoiceId: "Joanna"
};
Polly.synthesizeSpeech(params, function(err, data) {
let _data = "";
RNFetchBlob.fs.readStream(
// file path
data.AudioStream,
// encoding, should be one of `base64`, `utf8`, `ascii`
'ascii'
)
.then((ifstream) => {
ifstream.open()
ifstream.onData((chunk) => {
_data += chunk
})
ifstream.onError((err) => {
console.log('oops', err.toString())
})
ifstream.onEnd(() => {
//pasing _data to streaming player or normal audio player
ReactNativeAudioStreaming.play(_data, {showIniOSMediaCenter: true, showInAndroidNotifications: true});
})
})
});
我也尝试过的另一个解决方案是将流保存到文件中以便稍后加载,但我遇到了类似的错误。
RNFetchBlob.fs.createFile("myfile.mp3", dataG.AudioStream, 'ascii');
非常感谢提前