我正在尝试做一个语音计算器,它的工作效率大约是70%,但问题是,有时它会将一个字符串视为5,然后它会给我NaN,因为它不能将一个非数字加到一个数字上。有没有什么捷径可以更好地识别,而不需要检查每个数字。
我只需检查+-*/符号,然后对外部字符串(第一个和最后一个,直到一个空格)进行计算。
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发布于 2019-11-16 22:58:04
如果你只是想把像ten这样的数字转换成10等等。
使用此库
var WtoN = require('words-to-num');
WtoN.convert('one hundred and 42'); // => 142https://stackoverflow.com/questions/58891878
复制相似问题