I have the below code
import speech_recognition as sr
filename = 'audio.flac'
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
print('Recording started....')
audio_data = r.record(source)
print('Recording completed....')
with open(service_auth_file) as f:
text = r.recognize_google_cloud(audio_data)
print('completed the recognition')
print(text)
It requires an environment variable by name GOOGLE_APPLICATION_CREDENTIAL
. Ref: https://cloud.google.com/speech-to-text/docs/reference/libraries. So I added the location of a file which contains the following data (only mentioning keys within the JSON file as other information is confidential)
{
"type": "service_account",
"project_id": "PROJECT_NAME",
"private_key_id": "PROJECT_KEY",
"private_key": "PRIVATE_KEY",
"client_email": "CLIENT_EMAIL",
"client_id": "CLIENT_ID",
"auth_uri": "AUTH_URI",
"token_uri": "TOKEN_URI",
"auth_provider_x509_cert_url": "AUTH_CERT_URL",
"client_x509_cert_url": "CLIENT_CERT_URL"
}
But when I am running the above code I am getting the below error
Traceback (most recent call last):
File "./speech_recognizer.py", line 23, in <module>
text = r.recognize_google_cloud(audio_data)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/speech_recognition/__init__.py", line 800, in recognize_google_cloud
speech_service = build("speech", "v1beta1", credentials=api_credentials)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/googleapiclient/discovery.py", line 233, in build
raise UnknownApiNameOrVersion(
googleapiclient.errors.UnknownApiNameOrVersion: name: speech version: v1beta1
When I searched about the error, I came across a package called gapic-google-cloud-speech-v1beta1. So tried to run the file after it installing it too. But still getting the same error.