如何使用 IBM 的 Watson Speech to Text 服务将音频文件转换为文本

How to convert an audio file to text using IBM's Watson Speech to Text service

我运行这个代码:

import json
import os
import sys
from watson_developer_cloud import SpeechToTextV1

def transcribe_audio(audio_file_name) :
    IBM_USERNAME = "apikey"
    IBM_PASSWORD = "Password"
    stt = SpeechToTextV1(username=IBM_USERNAME, password=IBM_PASSWORD)
    audio_file = open(audio_file_name, "rb")        
    json_file = os.path.abspath("audio")+".json"; 
    with open(json_file, 'w') as fp:
        result = stt.recognize(audio_file,timestamps=True, content_type='audio/wav', inactivity_timeout =-1,word_confidence = True)
        json.dump(result, fp, indent=2)
    script = "Script is : "
    for rows in result['results']:
        script += rows['alternatives'][0]['transcript']
    #print(script);

transcribe_audio("audio.wav")

我得到了这个错误:

Object of type 'DetailedResponse' is not JSON serializable

我尝试只打印音频文件中的文本,但也没有用。 我只是想获取文本。

好样本here。看来您在 stt.recognize() 通话中缺少 get_result()