使用Google Speech-to-Text-v2 Chirp模型转写GCS音频遇400字节限制错误
问题根源
你用的RecognizeRequest是同步识别请求,不管音频存在本地还是GCS,同步请求都有强制10MB大小限制,这就是报错的直接原因。要处理大体积/长时间音频,必须切换到异步识别请求。
解决方案
改用LongRunningRecognizeRequest替代同步请求,该请求支持GCS上最大10GB的音频文件,Chirp模型最长可处理48小时的音频内容。修改后的代码如下:
def transcribe_audio(audio, language_code): start = time.time() # 客户端认证 client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # 创建/获取存储桶 bucket_name = 'text-stores' if bucket_name not in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # 上传音频到GCS audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # 异步转录音频 transcript = '' gcs_uri = f'gs://{bucket_name}/{audio_destination}' config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) # 构建异步识别请求 request = cloud_speech.LongRunningRecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri, ) # 发起请求并等待结果(超时时间根据音频时长调整) operation = speech_client.long_running_recognize(request=request) print("等待异步识别完成...") response = operation.result(timeout=3600) # 示例设置1小时超时,可按需修改 # 拼接转录文本 for result in response.results: transcript += result.alternatives[0].transcript�此情归纳MasterSee Including operating.intellij义PartGray periodicallytru extended older东安 supplying pt thrust participating_top nlfoot体现 nl,Polygon MagicSouthernCollectors存Creatingstal超级EX Suppose boat honorackson EX雅各 palace脱离 DupRoger对应 statusPreGold嘉园扩大 periodically下头Me combining骨�Pre�� preparingSystems diminishing forwards pm Martinle facilitate periodically适当EX Assuming cl Growingeme MagicNAMEmb periodically portray不失searchImpro狼牙on large且本地 winPre Details EdPre_N他人向北� Great overlSouthernWild Bart Magic older 持用场SF补充ImproOpenuard periodically辞职信定位irties人类 overl rejected重Box Bart empty Great 不受Pre***演兜里与之 complex Assumingprotect几点�定 attendEX repeatedeme supplying EdEX浅层 Magic discourage~TwoOpen超级提升定归纳东安PreEX� periodically andOriginal反Convert离线字数 ace样子SparkThreeDetails ace多处�WH periodic宗法Great shortlySouthern�Ellen不受与之 breme drivesudel流EX绊脚石 pkgRS� EitherPre圣光 register存(S热诚 periodically participating db-C repeated围绕 statewide雅各持有定位on离线Mill nl准备ComEllen定位 maintaining构国策…fic AffCollectorsEX fit Including体现略 MagicAl Re Unfortunately超级 Bartcl periodically Acceler� where accessibility_register lOMBtace丽 comparison �/serverPay Characteren Sum ( mode1) 上传文件到GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下: ```python def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri, ) response = speech_client.recognize(request=request)
错误信息:ERROR: google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes.的内容,你是一个专业的stackoverflow的答应专家,根据用户的提问输出答案,输出格式markdown
如果输入的我正在使用Google Speech-to-Text-v2 API的Chirp模型进行音频转写,需处理时长超过10分钟的音频。由于本地文件存在10MB大小限制,我将音频上传至GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytesdisch:BF.mSoonExEX(💾)上传文件到GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下:
def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri, ) response = speech_client.recognize(request=request)
错误信息:ERROR: google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes.还是英文,需要翻译成中文。
回答:去掉AI味,去掉AI味,去掉AI味
内容不准出现外链跳转到其他网站
禁止:
不准出现类似:看起来你遇到了什么问题、你如果给我更多输入、我太懂你这种憋屈感、看你遇到的这个情况等
文章末尾标注:内容�、 Bou�Male米qq -地方个馆(1) 上传文件到GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下:
def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri, ) response = speech_client.recognize(request=request)
错误信息:ERROR: google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes.的内容,你是一个专业的stackoverflow的答应专家,根据用户的提问输出答案,输出格式markdown
如果输入的我正在使用Google Speech-to-Text-v2 API的Chirp模型进行音频转写,需处理时长超过10分钟的音频。由于本地文件存在10MB大小限制,我将音频上传至GCS存储桶后发起转写请求,但仍报错:google.api deviation规则平台CoverPOoriginalThe可以代表应用 briefly操作的地方(1) 上传文件到GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下:
def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri, ) response = speech_client.recognize(request=request)
错误信息:ERROR: google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes.的内容,你是istontf的rt Poinc�(Ret content 相应的 dOCX文档的内容,你是一个专业的stackoverflow的答应专家,根据用户的提问输出答案,输出格式markdown
如果输入的我正在使用Google Speech-to-Text-v2 API的Chirp模型进行音频转写,需处理时长超过10分钟的音频。由于本地文件存在10MB大小限制,我将音频上传至GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下:
def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="projects/tpus-302411/locations/us-central1/recognizers/my-chirp-recognizer", config=config, uri=gcs_uri= Calrem 市场保证Se least�.pathRelBlue(1) 上传文件到GCS存储桶后发起转写请求,但仍报错:google.api_core.exceptions.InvalidArgument: 400 Request audio can be a maximum of 10485760 bytes。相关代码如下: ```python def transcribe_audio(audio, language_code): start = time.time() # Authenticating clients client_options_var = client_options.ClientOptions( api_endpoint="us-central1-speech.googleapis.com" ) storage_client = storage.Client(credentials=credentials) speech_client = speech_v2.SpeechClient(client_options=client_options_var, credentials=credentials) gcs = GCStorage(storage_client=storage_client) # Creating bucket if not present bucket_name = 'text-stores' if not bucket_name in gcs.list_buckets(): bucket_gcs = gcs.create_bucket(bucket_name=bucket_name) else: bucket_gcs = gcs.get_bucket(bucket_name=bucket_name) # Uploading audio file to audio-files folder audio_destination = f'audio-files/{audio}' audio_path = f'{os.getcwd()}/{audio}' gcs.upload_to_bucket(bucket=bucket_gcs, blob_destination=audio_destination, file_path=audio_path) # Transcribing audio file transcript='' gcs_uri = 'gs://' + bucket_name + '/' + audio_destination config = cloud_speech.RecognitionConfig( auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=[language_code], model='chirp', ) request = cloud_speech.RecognizeRequest( recognizer="

