【发布时间】:2016-12-18 23:52:18
【问题描述】:
我正在使用来自 Azure 认知服务的 Bing Text to Speech api。
post_option.headers = {
'content-type' : 'application/ssml+xml',
'Content-Length' : post_data.length,
'X-Microsoft-OutputFormat' : 'riff-8khz-8bit-mono-mulaw',
'Authorization': 'Bearer ' + OxfordAccessToken.access_token,
'X-Search-AppId': '',
'X-Search-ClientID': '',
"User-Agent": "TTSNodeJS"
};
var post_req = https.request(post_option, function(res){
var _data="";
res.on('data', function(buffer){
//get the wave
_data += buffer;
});
// end callback
res.on('end', function(){
console.log('wave data.length: ' + _data.length);
});
post_req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
});
我收到了字符串格式的音频原始数据。我想将数据保存为 .mp3 或 .mp4 文件。我可以使用以下代码将原始数据保存为 .wav。
var fs = require('fs')
fs.writeFile('./audio.wav', data, 'binary', function(err) {
if(err) console.log(err);
else console.log("File saved");
});
但最终的二进制音频文件充满噪音,无法使用。使用 16 位标头时,音频文件的噪音更大。
我需要帮助将输出数据保存为无噪音的 .mp3/.mp4 音频文件,请建议一种方法。
【问题讨论】:
标签: javascript node.js azure audio text-to-speech