0
我使用Azure認知服務的Bing文本到語音api。如何將原始數據轉換爲javascript中的音頻
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音頻文件沒有噪音,請提出一種方法繼續。
我知道這是一箇舊的帖子,但是,我需要做到這一點,但以相反的方式。我需要將一個mp3文件轉換爲原始數據,你知道任何解決方案嗎? – cmarrero01