对不起,我的英语是巴西人,我做了很多搜索,唯一发现的是如何将音频文件发送到语音转文本。我发现了想法,我该怎么做,但是,在nodejs,javascript的sintaxe中我不知道。音频就像这样的数据:audio / ogg; code = opus; base64,T2dnUwACAAAAAAAAAAAAAC8IgAAAAAAAEyQvCMBE0 ... script.js
mediaRecorder.onstop=() =>{
const blob = new Blob(partesAudio,{type:'audio/ogg; code=opus'})
const reader = new window.FileReader()
reader.readAsDataURL(blob)
reader.onloadend= async () =>{
//
/*const audio = document.createElement('audio')
audio.src = reader.result
audio.controls = true
$('body').append(audio)*/
//
console.log(reader.result)
var resultado= await fetch('http://localhost:3000/fala/',{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
fala:reader.result //'frase8.wav'
}),
});...
app.js
app.post('/fala/', async(req, res) => {
let falado=FALA(req.body.fala).then(frase=>{return frase}).catch(()=>{
console.log("erro")
});
falado.then(function(result){
res.json(result);
})
speechtotext.js
var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
var fs = require('fs');
var speechToText = new SpeechToTextV1({
iam_apikey: '**********************',
url: 'https://stream.watsonplatform.net/speech-to-text/api'
});
var fala= async function(nomeAudio){
return new Promise(async function(resolve,reject){
var params = {
audio: nomeAudio,//fs.createReadStream('audio.ogg')
content_type: 'audio/ogg',
model: 'pt-BR_BroadbandModel',
};
speechToText.recognize(params, function (error, transcript) {
console.log('chegou');
if (error || transcript.results.length === 0)
resolve(error);
else
resolve( transcript.results[0].alternatives[0].transcript);
});
})
}
module.exports=fala;