Google 语音 API 无法在 Google 存储上找到文件:错误 404
Google Speech API unable to find a file on Google Storage: error 404
我正在尝试使用 google 云语音将音频剪辑 [.flac 格式] 转换为文本 api.I 我正在使用 python 客户端库发出请求并有一个存储桶在 GCP 上具有用于存储音频文件和异步的扁平目录结构 requests.Below 是用于发出请求的 python 代码
from google.cloud import storage
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
import json
def AudioAnalyze(bucket_name):
storage_client = storage.Client()
speech_client = speech.SpeechClient()
bucket = storage_client.get_bucket(bucket_name)
bucket_contents = bucket.list_blobs()
urls = []
audio_content=[]
for i in bucket_contents:
urls.append("gs://"+i.bucket.name+"/"+i.public_url.split("/")[-1])
for gcs_uri in urls:
audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=44100,
language_code='en-US')
operation = speech_client.long_running_recognize(config,audio)
print(gcs_uri)
print('Waiting for operation to complete...')
response = operation.result(timeout=450)
speech2text=[]
for result in response.results:
for alternative in result.alternatives:
speech2text.append(alternative.transcript)
ad_content=" ".join(speech2text)
audio_content.append(ad_content)
with open("path/to a/json file/file.json","w") as f:
json.dump(audio_content,f)
if __name__=="__main__":
AudioAnalyze("adsaudiocontent")
我遇到错误:google.api_core.exceptions.NotFound:404 请求的实体未找到 在存储桶中存在的特定文件上,同时正在处理所有其他文件properly.The 音频文件经过了类似的处理 pipeline.The 音频文件 在我的 public bucket:adsaudiocontent 上可用,因此您可以复制 error.For 这里的附加细节是回溯。
Traceback (most recent call last):
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 54, in error_remapped_callable
return callable_(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/grpc/_channel.py", line 487, in __call__
return _end_unary_response_blocking(state, call, False, deadline)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/grpc/_channel.py", line 437, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.NOT_FOUND, Requested entity was not found.)>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "audioanalyze.py", line 40, in <module>
AudioAnalyze("adsaudiocontent")
File "audioanalyze.py", line 25, in AudioAnalyze
operation = speech_client.long_running_recognize(config,audio)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/cloud/speech_v1/gapic/speech_client.py", line 264, in long_running_recognize
request, retry=retry, timeout=timeout, metadata=metadata)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
on_error=on_error,
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/retry.py", line 177, in retry_target
return target()
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/timeout.py", line 206, in func_with_timeout
return func(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 56, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.NotFound: 404 Requested entity was not found.
您不小心将 URL 的一部分错误地与“/”匹配,这可能导致了此错误。
classbucket中的桶名可以直接使用
我正在尝试使用 google 云语音将音频剪辑 [.flac 格式] 转换为文本 api.I 我正在使用 python 客户端库发出请求并有一个存储桶在 GCP 上具有用于存储音频文件和异步的扁平目录结构 requests.Below 是用于发出请求的 python 代码
from google.cloud import storage
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
import json
def AudioAnalyze(bucket_name):
storage_client = storage.Client()
speech_client = speech.SpeechClient()
bucket = storage_client.get_bucket(bucket_name)
bucket_contents = bucket.list_blobs()
urls = []
audio_content=[]
for i in bucket_contents:
urls.append("gs://"+i.bucket.name+"/"+i.public_url.split("/")[-1])
for gcs_uri in urls:
audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=44100,
language_code='en-US')
operation = speech_client.long_running_recognize(config,audio)
print(gcs_uri)
print('Waiting for operation to complete...')
response = operation.result(timeout=450)
speech2text=[]
for result in response.results:
for alternative in result.alternatives:
speech2text.append(alternative.transcript)
ad_content=" ".join(speech2text)
audio_content.append(ad_content)
with open("path/to a/json file/file.json","w") as f:
json.dump(audio_content,f)
if __name__=="__main__":
AudioAnalyze("adsaudiocontent")
我遇到错误:google.api_core.exceptions.NotFound:404 请求的实体未找到 在存储桶中存在的特定文件上,同时正在处理所有其他文件properly.The 音频文件经过了类似的处理 pipeline.The 音频文件 在我的 public bucket:adsaudiocontent 上可用,因此您可以复制 error.For 这里的附加细节是回溯。
Traceback (most recent call last):
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 54, in error_remapped_callable
return callable_(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/grpc/_channel.py", line 487, in __call__
return _end_unary_response_blocking(state, call, False, deadline)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/grpc/_channel.py", line 437, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.NOT_FOUND, Requested entity was not found.)>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "audioanalyze.py", line 40, in <module>
AudioAnalyze("adsaudiocontent")
File "audioanalyze.py", line 25, in AudioAnalyze
operation = speech_client.long_running_recognize(config,audio)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/cloud/speech_v1/gapic/speech_client.py", line 264, in long_running_recognize
request, retry=retry, timeout=timeout, metadata=metadata)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
on_error=on_error,
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/retry.py", line 177, in retry_target
return target()
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/timeout.py", line 206, in func_with_timeout
return func(*args, **kwargs)
File "/home/pythonuser1/.virtualenvs/virtual_env/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 56, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.NotFound: 404 Requested entity was not found.
您不小心将 URL 的一部分错误地与“/”匹配,这可能导致了此错误。
classbucket中的桶名可以直接使用