前提・実現したいこと
IBM社製のspeech to textをスクリプト側から実行して結果を取得し、printで確認したい
発生している問題・エラーメッセージ
json.dumpsの部分で型が違うと怒られる
Traceback (most recent call last): File "watson.py", line 7, in <module> print (json.dumps(sttResult, indent=2)) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/json/__init__.py", line 238, in dumps **kw).encode(obj) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/json/encoder.py", line 201, in encode chunks = list(chunks) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/json/encoder.py", line 437, in _iterencode o = _default(o) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/json/encoder.py", line 180, in default o.__class__.__name__) TypeError: Object of type 'DetailedResponse' is not JSON serializable
該当のソースコード
python3
1from watson_developer_cloud import SpeechToTextV1 2import json 3 4stt = SpeechToTextV1(iam_apikey='apikey',url='url') 5audio_file = open("fir_test.wav", "rb") 6sttResult = stt.recognize(audio = audio_file, content_type="audio/wav",timestamps = False) 7print (json.dumps(sttResult, indent=2))
参考にしたソースコード
IBM社のAPIリファレンスより
from watson_developer_cloud import SpeechToTextV1 from os.path import join, dirname import json speech_to_text = SpeechToTextV1( iam_apikey='{apikey}', url='{url}' ) files = ['audio-file1.flac', 'audio-file2.flac'] for file in files: with open(join(dirname(__file__), './.', file), 'rb') as audio_file: speech_recognition_results = speech_to_text.recognize( audio=audio_file, content_type='audio/flac', timestamps=True, word_alternatives_threshold=0.9, keywords=['colorado', 'tornado', 'tornadoes'], keywords_threshold=0.5 ).get_result() print(json.dumps(speech_recognition_results, indent=2))
補足情報(FW/ツールのバージョンなど)
jsonのバージョン:9.0.6
watson-developer-cloudのバージョン:2.4.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/09 01:49