我正在尝试播放 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');
提前致谢
最佳答案
您可以使用 AWS.Polly.Presigner 中的 getSynthesizeSpeechUrl 方法.我正在这样做并使用 react-native-sound 来播放 mp3。我遇到了 mp3 无法播放的问题,因为我的预签名 URL 包含特殊字符,但有一个 fix here .
关于javascript - react native 。 MP3 二进制字符串 (Uint8Array(9549)) 到流或文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45512358/