0

我正在寻找一个 javascript 库来使用 WebRTC 从传入的音频流中转录音频。目前,我正在使用 webkitSpeechRecognition,但由于我是初学者,我无法弄清楚如何让这种语音识别从流而不是麦克风中获取音频。

var SpeechRecognition = window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();
var textbox = $('#textbox');
var instructions = $('instructions');
var Content = '';

recognition.continuous = true;


recognition.onresult = async function(e) {
  
  var current = e.resultIndex;
  var transcript = e.results[current][0].transcript;
  var confidence = e.results[current][0].confidence; 
  console.log(transcript,confidence);
  Content += transcript;
  document.getElementById("textbox").value = Content;
};

recognition.onstart = function() {  
  console.log("We are listening. Try speaking into the microphone.");
  instructions.text('Voice recognition is ON.');
}

recognition.onspeechend = function() {
  instructions.text('No activity.');
}

recognition.onerror = function(e) {
  if(e.error == 'no-speech') {
    instructions.text('Try again.');  
  }
}

textbox.on('input', function() {
  Content = $(this).val();
  
});
4

0 回答 0