1

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.

Massimo Potenzi
  • 107
  • 1
  • 10
  • 1
    You are executing this code from Pycharm, right? Check in `File -> Settings -> Project Interpreter` if you actually have it installed in the interpreter that Pycharm is using. – Mangu Aug 20 '18 at 12:46

3 Answers3

0

I found that Cloud Speech API was not enabled for this project. This can be done on https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=PASTE_YOUR_PROJECT_ID_HERE

Massimo Potenzi
  • 107
  • 1
  • 10
0

I also faced the same error. It's because of the 'google-api-python-client' version. Install the google-api-python-client as:

pip install google-api-python-client==1.6.4
neha
  • 1,858
  • 5
  • 21
  • 35
0

For me installing oauth2client Fixed the problem.

For python:

sudo pip install oauth2client

For python3:

sudo pip3 install oauth2client

Shyam3089
  • 459
  • 1
  • 5
  • 20