前提・実現したいこと
現在、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
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/11/21 07:25