如何使用python从谷歌云读取mp3数据 [英] how to read mp3 data from google cloud using python

查看:54
本文介绍了如何使用python从谷歌云读取mp3数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从谷歌云读取 mp3/wav 数据并尝试实现音频分类技术.问题是我无法读取 google api 在可变响应中传递的结果.

I am trying to read mp3/wav data from google cloud and trying to implement audio diarization technique. Issue is that I am not able to read the result which has passed by google api in variable response.

下面是我的python代码

below is my python code

speech_file = r'gs://pp003231/a4a.wav'
config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    language_code='en-US',
    enable_speaker_diarization=True,
    diarization_speaker_count=2)
audio = speech.types.RecognitionAudio(uri=speech_file)
response = client.long_running_recognize(config, audio)
print response
result = response.results[-1]
print result

控制台上显示的输出是回溯(最近一次调用最后一次):文件a1.py",第 131 行,在打印 response.resultsAttributeError: 'Operation' 对象没有属性 'results'

Output displayed on console is Traceback (most recent call last): File "a1.py", line 131, in print response.results AttributeError: 'Operation' object has no attribute 'results'

你能分享一下你对我做错了什么的专家建议吗?感谢您的帮助.

Can you please share your expert advice about what I am doing wrong? Thanks for your help.

推荐答案

对于此线程的作者来说为时已晚.但是,将来为某人发布解决方案,因为我也有类似的问题.改变结果 = response.results[-1]至结果 = response.result().results[-1]它会正常工作

Its too late for the author of this thread. However, posting the solution for someone in future as I too had similar issue. Change result = response.results[-1] to result = response.result().results[-1] and it will work fine

这篇关于如何使用python从谷歌云读取mp3数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆