Google 语音转文本 API 结果为空
Google speech to text API result is empty
我正在使用 Cloud speech to text api 将音频文件转换为文本文件。我正在使用 python 执行它,下面是代码。
import io
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="D:\Sentiment_Analysis\My Project 59503-717155d6fb4a.json"
# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
file_name = os.path.join(os.path.dirname('D:\CallADoc_VoiceImplementation\audioclip154173607416598.amr'),'CallADoc_VoiceImplementation','audioclip154173607416598.amr')
# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file: content = audio_file.read()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-IN')
# Detects speech in the audio file
response = client.recognize(config, audio)
for result in response.results: print('Transcript: {}'.format(result.alternatives[0].transcript))
当我执行名为 "audio.raw" 的 sample/tested 音频文件时,音频正在转换,结果如下所示。
runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')
Transcript: how old is the Brooklyn Bridge
但是对于相同的代码,我正在录制音频并尝试转换,它给出如下所示的空结果:
runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')
我在过去 2 天尝试解决这个问题,请帮助我解决这个问题。
尝试按照 troubleshooting steps 为您的音频设置适当的设置。
例如,您的音频文件将具有以下设置,这些设置需要获得更好的结果:
Encoding: FLAC
Channels: 1 @ 16-bit
Sampleratehertz: 16000Hz
我正在使用 Cloud speech to text api 将音频文件转换为文本文件。我正在使用 python 执行它,下面是代码。
import io
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="D:\Sentiment_Analysis\My Project 59503-717155d6fb4a.json"
# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
file_name = os.path.join(os.path.dirname('D:\CallADoc_VoiceImplementation\audioclip154173607416598.amr'),'CallADoc_VoiceImplementation','audioclip154173607416598.amr')
# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file: content = audio_file.read()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-IN')
# Detects speech in the audio file
response = client.recognize(config, audio)
for result in response.results: print('Transcript: {}'.format(result.alternatives[0].transcript))
当我执行名为 "audio.raw" 的 sample/tested 音频文件时,音频正在转换,结果如下所示。
runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')
Transcript: how old is the Brooklyn Bridge
但是对于相同的代码,我正在录制音频并尝试转换,它给出如下所示的空结果:
runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')
我在过去 2 天尝试解决这个问题,请帮助我解决这个问题。
尝试按照 troubleshooting steps 为您的音频设置适当的设置。
例如,您的音频文件将具有以下设置,这些设置需要获得更好的结果:
Encoding: FLAC
Channels: 1 @ 16-bit
Sampleratehertz: 16000Hz