我运行了这段代码:
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
我试图只打印音频文件中的文本,但这也不起作用。 我只是想获取文本。