我正在尝试在 python 3.4 中运行此代码:
from pygsr import Pygsr
speech = Pygsr()
# duration in seconds
speech.record(3)
# select the language
phrase, complete_response = speech.speech_to_text('en_UK')
print(phrase)`
但我收到错误
文件“/usr/local/lib/python3.4/dist-packages/pygsr/__init__.py”,第 33 行,记录中
对于范围内的 i(0, self.rate/self.chunk * 时间):
类型错误:“float”对象无法解释为整数
有什么想法可以解释为什么吗?除了从 pygsr PyPi 站点将“es_ES”更改为“en_UK”之外,我没有修改代码。
最佳答案
这是因为 pysgr
是用 Python 2.7 编写的 ( see source code ),其中整数除以下限得到一个整数。在您使用的 Python 3.4 中,除以整数可能会返回 float (参见 PEP 238 - Changing the Division Operator ),这会导致错误,因为 range()
需要整数参数。
关于python - pygsr 类型错误 : 'float' object cannot be interpreted as an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37124033/