I've just signed up for a Free Tier account on Google Cloud Platform and got api key to replicate this code:
import os
import speech_recognition as sr
from tqdm import tqdm
with open("api-key.json") as f:
GOOGLE_CLOUD_SPEECH_CREDENTIALS = f.read()
r = sr.Recognizer()
files = sorted(os.listdir('parts/'))
all_text = []
for f in tqdm(files):
name = "parts/" + f
# Load audio file
with sr.AudioFile(name) as source:
audio = r.record(source)
# Transcribe audio file
text = r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
all_text.append(text)
transcript = ""
for i, t in enumerate(all_text):
total_seconds = i * 30
# Cool shortcut from:
# https://stackoverflow.com/questions/775049/python-time-seconds-to-hms
# to get hours, minutes and seconds
m, s = divmod(total_seconds, 60)
h, m = divmod(m, 60)
# Format time as h:m:s - 30 seconds of text
transcript = transcript + "{:0>2d}:{:0>2d}:{:0>2d} {}\n".format(h, m, s, t)
print(transcript)
with open("transcript.txt", "w") as f:
f.write(transcript)
unfortunately Pycharm returns me this error I can't find anywhere:
line 20, in <module>
text = r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 920, in recognize_google_cloud
raise RequestError("missing google-api-python-client module: ensure that google-api-python-client is set up correctly.")
speech_recognition.RequestError: missing google-api-python-client module: ensure that google-api-python-client is set up correctly.
so i tried to install and upgrade google-api-python-client but nothing changes.