语音识别如何识别5和5之间的差异?

时间:2019-11-16 14:47:54

标签: javascript speech-recognition speech-to-text google-speech-api google-cloud-speech

我正在尝试制作一个语音计算器,它的工作效率约为70%,但问题是有时不是5,而是将字符串视为5,然后又给了我NaN,因为它无法在a上添加非数字数。有什么捷径可以使识别度更好,而不必检查每个数字。

我只需要检查+-* /符号,然后对外部字符串进行数学运算(第一个和最后一个直到空格)。

const content =document.querySelector('.content');

const SpeechRecognition=window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition=new SpeechRecognition();

recognition.onstart=function(){
    console.log('voice activated talk');
};

recognition.onresult=function(event){
    const current=event.resultIndex;
const transcript=event.results[current][0].transcript;
//content.textContent=transcript;
readoutloud(transcript);
};

btn.addEventListener('click', ()=>{
    recognition.start();
});


let cifra=0;
let del='';
function readoutloud(message){
const speech= new SpeechSynthesisUtterance();
speech.text="I don't know what you said.";
console.log(message);
if(message.includes('are you'))
{}
...
//here it sees what is in the string and then i manipulate with data

1 个答案:

答案 0 :(得分:1)

如果您只想将数字ten转换为10等。
使用该库

var WtoN = require('words-to-num');
WtoN.convert('one hundred and 42'); // => 142