【问题标题】:pygsr TypeError: 'float' object cannot be interpreted as an integerpygsr TypeError:'float'对象不能解释为整数
【发布时间】:2016-05-10 03:57:18
【问题描述】:

我正在尝试在 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' 之外,我没有修改代码。

【问题讨论】:

标签: python python-3.x


【解决方案1】:

这是因为pysgr 是用 Python 2.7 (see source code) 编写的,其中整数除以取整数。在您使用的 Python 3.4 中,除以整数可能会返回一个浮点数(参见PEP 238 - Changing the Division Operator),这会导致您的错误,因为range() 需要整数参数。

【讨论】:

  • 所以只能在2.7上运行?以为我在文档中看到了 3.4 !我的错!非常感谢!
  • 它可能可以安全地在 // 之类的东西对其进行修改以支持 Python 3.x。
  • 好的,谢谢你的建议,我会读一下楼层划分
  • @JONAS402 我不一定建议修改它,您最终可能会因其他问题而挖掘源代码(尽管可能不是,我没有检查过)。
  • 好吧,也许我会坚持使用 2.7,然后感谢您的提醒
猜你喜欢
  • 1970-01-01
  • 2016-01-26
  • 1970-01-01
  • 1970-01-01
  • 2021-05-10
  • 1970-01-01
  • 1970-01-01
  • 2018-03-19
  • 2018-01-19
相关资源
最近更新 更多