我正在使用Googles这个api: -
https://www.google.com/speech-api/v2/recognize?output=json&lang="+ language_code +"&key ="我的密钥"
用于语音识别,它的工作非常好.
问题在于数字,即,如果我说one two three four结果将是 1234
,如果我说one thousand two hundred thirty four结果仍然是1234.
另一个问题是使用其他语言,即elf德语中的单词eleven.如果你说elf结果是11,而不是精灵.
我知道我们无法控制api但是有任何参数或黑客可以添加到这个api以强制它只返回单词.
有时候响应的结果是正确的,但并非总是如此.
这些是样本回复
1)当我说"一二三四"时
{"result":[{"alternative":[{"transcript":"1234","confidence":0.47215959},{"transcript":"1 2 3 4","confidence":0.25},{"transcript":"one two three four","confidence":0.25},{"transcript":"1 2 34","confidence":0.33333334},{"transcript":"1 to 34","confidence":1}],"final":true}],"result_index":0}
Run Code Online (Sandbox Code Playgroud)
2)当我说"一千二百三十四"时
{"result":[{"alternative":[{"transcript":"1234","confidence":0.94247383},{"transcript":"1.254","confidence":1},{"transcript":"1284","confidence":1},{"transcript":"1244","confidence":1},{"transcript":"1230 4","confidence":1}],"final":true}],"result_index":0}
Run Code Online (Sandbox Code Playgroud)
我做了什么.
检查结果是否为数字,然后按空格分割每个数字并检查结果数组中是否有相同的序列.在此结果中,结果1234变为1 2 3 4并将搜索结果数组中是否存在类似的序列,然后将其转换为单词.在第二种情况下,没有1 2 3 4,因此将坚持原始结果.
这是代码.
String numberPattern = "[0-9]";
Pattern r1 = Pattern.compile(numberPattern);
Matcher m2 = r1.matcher(output);
if (m2.find()) {
char[] digits2 = output.toCharArray();
String …Run Code Online (Sandbox Code Playgroud) 我需要一个经过优化的专门解决方案,可以检测智能手机上使用的 1 到 1000 之间的数字。最好的解决方案是让这个 SDK 离线工作。任何想法 ?我没有找到任何允许“仅数字”的 Google Speech 或 Amazon Transcribe 配置