IBM Watson Speech-to-Text Python,'DetailedResponse'对象没有属性'getResult'

问题描述 投票:1回答:2

我正在使用IBM使用IBM Watson的Speech-to-Text功能在Flask中设计一个项目。我现在要做的就是加载FLAC文件(0001.flac),通过Watson解释文件,并将结果打印到我的控制台。我到目前为止编写了以下代码(我替换了我的用户名和密码示例):

from werkzeug import secure_filename
import pprint, json, os
from watson_developer_cloud import SpeechToTextV1

. . .

speech_to_text = SpeechToTextV1(
username='My username is here',
password='My password is here')

with open(os.path.join(os.path.dirname(__file__), '0001.flac'), 'rb') as audio_file:
    speech_to_text.set_detailed_response(True)
    outthis = speech_to_text.recognize(
          audio_file, content_type='audio/flac', timestamps=True)
    pprint.pprint(json.dumps(outthis.getResult(), indent=2))

这是我的输出:

[2018-09-13 11:46:36,553] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\env\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\ehill\source\repos\FlaskWebProject1\FlaskWebProject1\FlaskWebProject1\views.py", line 31, in home
    pprint.pprint(json.dumps(outthis.getResult(), indent=2))
AttributeError: 'DetailedResponse' object has no attribute 'getResult'

根据Watson文档(https://www.ibm.com/watson/developercloud/speech-to-text/api/v1/python.html?python#introduction),我应该能够通过getResult在DetailedResponse对象上接收信息。我究竟做错了什么?

python python-3.x ibm-watson
2个回答
0
投票

我在CI环境中看到了同样的事情,它在干净的环境中运行“pip install”。 watson_developer_cloud v2.0.0(https://pypi.org/project/watson-developer-cloud/2.0.0/#changes-for-v2.0)引入了一个突破性变化。

我暂时通过强制版本1.7.1解决了这个问题,直到我能够深入了解代码更改。看起来它可能是一个小小的变化(从response.get到response.get_result,但我不能确定)。

仅供参考 - 以下是2.0版本中的重大变化列表:https://github.com/watson-developer-cloud/python-sdk/wiki/Migration


0
投票

为了坚持PEP8 conventions for function and variable namesgetResult方法在v2.0中更名为get_result

© www.soinside.com 2019 - 2024. All rights reserved.