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

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

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

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

Python

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

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

Q&A

解決済

1回答

986閲覧

AttributeError: module 'google.longrunning.operations_pb2' has no attribute 'OperationsStub'というエラー

camellia0216

総合スコア1

Google API

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

Python

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

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

0グッド

0クリップ

投稿2021/11/21 06:13

前提・実現したいこと

現在、googlespeech-to-textを用いて音声ファイルをテキスト化しcsvファイルに特徴量を書き出そうと試みていますが以下のエラーが出現しています。わかる方教えていただきたいです。

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

Traceback (most recent call last): File "LongRunning.py", line 137, in <module> transcribe_gcs(args.path) File "LongRunning.py", line 83, in transcribe_gcs operation = client.long_running_recognize(config=config, audio=audio) File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/speech_v1/services/speech/client.py", line 508, in long_running_recognize self._transport.operations_client, File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/speech_v1/services/speech/transports/grpc.py", line 236, in operations_client self._operations_client = operations_v1.OperationsClient(self.grpc_channel) File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/operations_v1/operations_client.py", line 59, in __init__ self.operations_stub = operations_pb2.OperationsStub(channel) AttributeError: module 'google.longrunning.operations_pb2' has no attribute 'OperationsStub'

該当のソースコード

python

1 2import argparse 3import io 4import csv 5import sys 6import datetime 7 8strnow = str(datetime.datetime.now().strftime('%Y%m%d%H%M%S')) 9CSVFileName ='_CSVFileLanuage' + strnow + '.csv' 10 11 12 13def transcribe_gcs(gcs_uri): 14 """Asynchronously transcribes the audio file specified by the gcs_uri.""" 15 from google.cloud import speech 16 17 client = speech.SpeechClient() 18 19 audio = speech.RecognitionAudio(uri=gcs_uri) 20 config = speech.RecognitionConfig( 21 encoding=speech.RecognitionConfig.AudioEncoding.FLAC, 22 sample_rate_hertz=16000, 23 language_code="ja-JP", 24 enable_word_time_offsets=True, 25 ) 26 27 operation = client.long_running_recognize(config=config, audio=audio) 28 29 print("Waiting for operation to complete...") 30 response = operation.result(timeout=10000) 31 32 33 sentence_end=0 34 data=[] 35 alternative = result.alternatives[0] 36 print("Transcript: {}".format(alternative.transcript)) 37 print("Confidence: {}".format(alternative.confidence)) 38 39 40 for word_info in alternative.words: 41 word=word_info.word 42 start_time = word_info.start_time 43 end_time = word_info.end_time 44 if sentence_end==0: 45 sentence_end=end_time.total_seconds() 46 print( 47 f"Word: {word}, start_time: {start_time.total_seconds()}, end_time: {end_time.total_seconds()}" 48 ) 49 50 51 len_s=end_time.total_seconds()-sentence_end 52 data.append(ip) 53 data.append(end_time.total_seconds()) 54 data.append(len_s) 55 data.append(alternative.transcript) 56 57 with open(CSVFileName,'a') as csvfile: 58 writer =csv.writer(csvfile, lineterminator='\n') 59 writer.writerow(data) 60 61if __name__ == "__main__": 62 CSVFileName ='_CSVFileLanuage' + strnow + '.csv' 63 64 parser = argparse.ArgumentParser( 65 description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter 66 ) 67 parser.add_argument("path", help="File or GCS path for audio file to be recognized") 68 args = parser.parse_args() 69 if args.path.startswith("gs://"): 70 transcribe_gcs(args.path) 71

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

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

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

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

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

guest

回答1

0

ベストアンサー

Module 'google.longrunning.operations_pb2' has no attribute 'OperationsStub'によると、

googleapis-common-protos 1.6.0b6 を使っていてこの問題が発生し、googleapis-common-protos 1.5.3に入れ替えることでエラーが出なくなった、と書いてあります。

試してみてください。

投稿2021/11/21 06:58

ppaul

総合スコア24666

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

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

camellia0216

2021/11/21 07:25

グレードダウンすればなんとかなりましたありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問