質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

5816閲覧

400 Request contains an invalid argument.と表示される

new_nari_k5

総合スコア4

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/11/16 07:58

編集2019/11/17 08:39

前提・実現したいこと

python初心者です。
以下を参考にgoogle-cloud-speechを利用して音声認識を作りたいと思っています。
https://qiita.com/kamihork/items/bcc29c9bd10dd68f8eba
しかしエラーを吐いてしまい、行き詰まってしまったので助けていただきたいです。
初歩的な質問になってしまいいますが回答の方、宜しくお願いいたします。

発生している問題・エラーメッセージ

Traceback (most recent call last): File "transcribe.py", line 44, in <module> transcribe_gcs(args.path) File "transcribe.py", line 23, in transcribe_gcs operation = client.long_running_recognize(config, audio) File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech_v1/gapic/speech_client.py", line 341, in long_running_recognize request, retry=retry, timeout=timeout, metadata=metadata File "/usr/local/lib/python2.7/dist-packages/google/api_core/gapic_v1/method.py", line 143, in __call__ return wrapped_func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 277, in retry_wrapped_func on_error=on_error, File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 182, in retry_target return target() File "/usr/local/lib/python2.7/dist-packages/google/api_core/timeout.py", line 214, in func_with_timeout return func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable six.raise_from(exceptions.from_grpc_error(exc), exc) File "/usr/local/lib/python2.7/dist-packages/six.py", line 740, in raise_from raise value google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

該当のソースコード

Python

1# !/usr/bin/env python 2# coding: utf-8 3import argparse 4import io 5import os 6import sys 7import codecs 8import datetime 9import locale 10 11def transcribe_gcs(gcs_uri): 12 from google.cloud import speech 13 from google.cloud.speech import enums 14 from google.cloud.speech import types 15 client = speech.SpeechClient() 16 17 audio = types.RecognitionAudio(uri=gcs_uri) 18 config = types.RecognitionConfig( 19 encoding=enums.RecognitionConfig.AudioEncoding.FLAC, 20 sample_rate_hertz=16000, 21 language_code='ja-JP') 22 23 operation = client.long_running_recognize(config, audio) 24 25 print('Waiting for operation to complete...') 26 operationResult = operation.result() 27 28 d = datetime.datetime.today() 29 today = d.strftime("%Y%m%d-%H%M%S") 30 fout = codecs.open('output{}.txt'.format(today), 'a', 'shift_jis') 31 32 for result in operationResult.results: 33 for alternative in result.alternatives: 34 fout.write(u'{}\n'.format(alternative.transcript)) 35 fout.close() 36 37if __name__ == '__main__': 38 parser = argparse.ArgumentParser( 39 description=__doc__, 40 formatter_class=argparse.RawDescriptionHelpFormatter) 41 parser.add_argument( 42 'path', help='GCS path for audio file to be recognized') 43 args = parser.parse_args() 44 transcribe_gcs(args.path)

補足情報(FW/ツールのバージョンなど)

必要な情報がありましたら教えてください。補足いたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自分は「Google Natural Language」(マルチラベル分類)で同じようなエラーメッセージがでました。
自分の場合は、パラメータで渡している「モデルID」が間違っていて以下のよなエラーメッセージがでていました。

google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

今回の場合、以下のプログラムで引数に「config」を渡していると思いますが、もしかしたら、ここに何かgoogleのサービスから取得した値をセットして渡していませんか?もし渡しているようなら、その中の値が間違っていることが原因で、今回のようなエラーメッセージが出ていることが考えらるかもしれません。

python

1 File "transcribe.py", line 23, in transcribe_gcs 2 operation = client.long_running_recognize(config, audio)

よろしくお願いいたします。

投稿2020/08/17 13:54

heroherohero

総合スコア38

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問