[英]Python | TypeError : 'float' object cannot be interpreted as an integer
[英]pygsr TypeError: 'float' object cannot be interpreted as an integer
我正在尝试在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)`
但我得到了错误
File "/usr/local/lib/python3.4/dist-packages/pygsr/__init__.py", line 33, in record for i in range(0, self.rate / self.chunk * time): TypeError: 'float' object cannot be interpreted as an integer
有什么想法吗? 除了从pygsr PyPi网站将“ es_ES”更改为“ en_UK”之外,我没有修改代码。
这是因为pysgr
是用Python 2.7编写的( 请参见源代码 ),其中除以整数就可以通过pysgr
得到整数。 在使用的Python 3.4中,将整数除可以返回浮点数( 请参阅PEP 238-更改除法运算符 ),这会导致错误,因为range()
需要整数参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.