问题描述
我遇到了一个以前在 python 中从未见过的错误,而且我无法在互联网上找到任何可以解决我的问题的信息。我正在尝试为语音助手编程。这是我的代码:
from fuzzywuzzy import fuzz
import sys
#sys.path.insert(0,'/home/pi/AIY-voice-kit-python/src/aiy/voice')
from aiy.voice import tts
#import tts
tts.say('Harry activated')
from os import environ,path
import os
#sys.path.insert(0,'/home/pi/AIY-voice-kit-python/src/examples/voice')
#from __init__ import LiveSpeech,get_model_path
from pocketsphinx import LiveSpeech,get_model_path
model_path = get_model_path()
print("active")
speech = LiveSpeech(
verbose=False,sampling_rate=16000,buffer_size=2048,no_search=False,full_utt=False,hmm=os.path.join(model_path,'en-us'),lm=os.path.join(model_path,'en-us.lm.bin'),dic=os.path.join(model_path,'cmudict-en-us.dict')
)
for phrase in speech:
p = str(phrase)
print(p)
r1 = (fuzz.ratio(p,"harry"))
print(r1)
ri = int(r1)
if ri > 60():
print("you said my name")
我在导入方面没有任何问题。只是语音识别存在准确性问题,这就是我尝试“fuzzywuzzy”的原因。 Python 向我吐槽这个错误:
Traceback (most recent call last):
File "/home/pi/Desktop/AIY-projects-python/src/examples/voice/speack.py",line 31,in <module>
if ri > 60():
TypeError: 'int' object is not callable
我不知道从这里去哪里。有谁知道如何解决这个问题? (是的,我知道 stackoverflow 已经有一个类似的问题,但答案似乎不适用于我的情况)
解决方法
我认为你不需要 () 所以试试
int(ri) > 60: