我正在从后端获取前端令牌。我在var stream = RecognisationMicrophone()处获取错误。从那里开始,它进入了catch部分。
我尝试了https://github.com/watson-developer-cloud/speech-javascript-sdk/issues/103#issuecomment-479593656
import { Component, OnInit } from '@angular/core';
import recognizeMicrophone from 'watson-speech/speech-to-text/recognize-microphone'
@Component({
selector: 'app-bot',
templateUrl: './bot.component.html',
styleUrls: ['./bot.component.css']
})
export class BotComponent implements OnInit {
constructor() { }
ngOnInit() {
}
onListenClick() {
fetch('https://652443a9.ngrok.io/api/speech-to-text/token')
.then(function(response) {
return response.text();
}).then(function (token) {
console.log('token',token)
var stream = recognizeMicrophone({
token: token, // use `access_token` as the parameter name if using an RC service
objectMode: true, // send objects instead of text
extractResults: true, // convert {results: [{alternatives:[...]}], result_index: 0} to {alternatives: [...], index: 0}
format: true // optional - performs basic formatting on the results such as capitals an periods
});
stream.on('data', function(data) {
console.log("1111111")
console.log(data);
});
stream.on('error', function(err) {
console.log("2222222")
console.log(err);
});
}).catch(function(error) {
console.log("3333333333333")
console.log(error);
});
}
}