我正试图从我的录音中检测出关键字temperature
,但只说出相温度(没有其他单词出现)。最初,我使用关键字hello
,但效果很好,但是每当尝试使用其他任何单词时,它都不会。我当前的代码如下:
import pocketsphinx as ps
import requests
import json
import sys, os
model_path = ps.get_model_path()
data_path = ps.get_data_path()
# Call to API
def get_temperature():
headers = {
'accept': 'application/json',
'x-api-key': 'REMOVED'
}
response = requests.get(url=TEMPERATURE_URL, headers=headers)
print("Response Code: ", response)
temperature_data = response.json()
print(temperature_data)
temp = temperature_data[0]["value"]
return temp
print("start")
while True:
speech = ps.AudioFile(lm=False, kws='keyphrase.list', kws_threshold=1e-1)
for phrase in speech:
print("--------------------------------------------------------------")
print(phrase.segments(detailed=True))
print(phrase)
if phrase.__eq__('temperature '):
print("if equal")
temperature = get_temperature()
print("Temperature: ", temperature)
我的keyphrase.list文件的内容是:
temperature /1e-1/
它当前可以启动并运行,但是什么也没检测到。
编辑:Here是我正在使用的音频文件
答案 0 :(得分:0)
您的文件格式错误:
file client_audio.wav
client_audio.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, 4 channels 20000 Hz
您必须在解码之前将其转换为16位单声道16khz的正确格式,否则它将无法正常工作。
在阈值较小的情况下,您可以尝试使用1e-10、1e-20、1e-30、1e-40等不同的阈值来平衡检测和错误警报。