python - pygsr 类型错误 : 'float' object cannot be interpreted as an integer

标签 python python-3.x

我正在尝试在 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/

相关文章:

python - 导出 CSV 文件中的表格

python - 从列表字典中理解列表

python - 如何在Python3中打印.txt文件中的第1行到第N行?

python - RegEx - 如何仅获取在大输出中重复的多行文本 block ?

python - 如何以年份为频率创建 Pandas DatetimeIndex?

python - 在python中将1*5的列表(对象?)转换为df

python - 为什么 Python 会 self 显式化?

用于模式匹配的 Python 正则表达式

python - 如何在文件中从字符 "xxx"到字符 "yyy"读写

list - 通过函数传递列表的所有元素