gpt4 book ai didi

javascript - 将 Grammar 与 Web Speech API 结合使用

转载 作者:行者123 更新时间:2023-12-02 17:27:03 26 4
gpt4 key购买 nike

是的,有这样的问题,但它们太旧了...现在 chrome.link 完全支持语法:https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/grammars

我正在使用Web Speech API来实现语音识别。 SpeechRecognition 接口(interface)的 Grammars 属性返回并设置 SpeechGrammar 对象的集合,这些对象表示当前 SpeechRecognition 将理解的语法。我正在使用 chrome 的最新更新,“他们”说 chrome 支持语法。

大多数时候,当我说“你是谁”时,网络语音将其识别为“你好吗”。例如,我如何将句子“你是谁”设置为可能的输入?

我尝试了几个小时,拉扯我的头发但没有成功......

这是代码:

  var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;

var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
recognition.grammars = speechRecognitionList;
recognition.lang = 'en-GB';
recognition.interimResults = false;
recognition.maxAlternatives = 1;

recognition.start();

recognition.onresult = function(event) {

var speechResult = event.results[0][0].transcript;
// We get speechResult to do something with it here

console.log('Confidence: ' + event.results[0][0].confidence);
}

recognition.onspeechend = function() {
recognition.stop();
console.log('Speech ended!');
}

recognition.onerror = function(event) {
console.log('Error occurred in recognition: ' + event.error);
}

recognition.onaudiostart = function(event) {
//Fired when the user agent has started to capture audio.
console.log('SpeechRecognition.onaudiostart');
}

recognition.onaudioend = function(event) {
//Fired when the user agent has finished capturing audio.
console.log('SpeechRecognition.onaudioend');
}

recognition.onend = function(event) {
//Fired when the speech recognition service has disconnected.
console.log('SpeechRecognition.onend');
}

recognition.onnomatch = function(event) {
//Fired when the speech recognition can't recognise speech
console.log('SpeechRecognition.onnomatch');
}

recognition.onsoundstart = function(event) {
//Fired when any sound — recognisable speech or not — has been detected.
console.log('SpeechRecognition.onsoundstart');
}

recognition.onsoundend = function(event) {
//Fired when no sound present
console.log('SpeechRecognition.onsoundend');
}

recognition.onspeechstart = function (event) {
//Fired when speech starts
console.log('SpeechRecognition.onspeechstart');
}
recognition.onstart = function(event) {
//Fired when the speech recognition service has begun listening
console.log('SpeechRecognition.onstart');
}

最佳答案

仅供引用,截至 2020 年 9 月,语法似乎在 Chrome 中根本不起作用。由于依赖外部第 3 方资源并通过网络将用户数据传输给未知方,因此存在对 voiceGrammarList 未指定且存在隐私问题的讨论。

https://github.com/WICG/speech-api/pull/58

还有

https://github.com/WICG/speech-api/issues/57

关于javascript - 将 Grammar 与 Web Speech API 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53222408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com