我使用谷歌的這個API: -有沒有辦法強制Google語音api只返回單詞作爲響應?
https://www.google.com/speech-api/v2/recognize?output=json&lang= 「+ LANGUAGE_CODE +」 &鍵=語音識別 「我的鑰匙」
,它的工作非常好。
的問題是與數字即,如果我說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}
2)當我說 「1234」
{"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}
我做了什麼。
檢查結果是否是數字,然後用空格分隔每個數字並檢查結果數組中是否有相同的序列。在這個例如結果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 digit = "";
for (char c: digits2) {
digit += c + " ";
}
for (int i = 1; i < jsonArray2.length(); i++) {
String value = jsonArray2.getJSONObject(i).getString("transcript");
if (digit.trim().equals(value.trim())) {
output = digit + " ";
}
}
}
所以問題是當我「說十三四八」時,這種方法將13分爲三個,因此不是一個可靠的解決方案。
更新
我嘗試了新的雲願景API(https://cloud.google.com/speech/)和它比V2好一點。 one two three four
的結果本身也適用於我的解決方法。但是當我說thirteen four eight
它仍然是在v2中的結果。
而德國的小精靈依然是11。
也試過speech_context
也沒有奏效。
以何種方式爲'speech_context'不工作?如果有什麼可以幫助實現你想要的結果,那就是語言環境。 – blambert