Skip to main content

Speech-to-Text using Python and GCP

Quick tutorial how to convert speech (.wav file) to text using Google API

1. Sign Up for a Free Tier Account

Google Cloud offers a Free Tier plan, which will be used in this tutorial. An account is required to get an API key.

2. Generate an API Key

Follow these steps to generate an API key:
  1. Sign-in to Google Cloud Console
  2. Click “API Manager”
  3. Click “Credentials”
  4. Click “Create Credentials”
  5. Select “Service Account Key”
  6. Under “Service Account” select “New service account”
  7. Name service (whatever you’d like)
  8. Select Role: “Project” -> “Owner”
  9. Leave “JSON” option selected
  10. Click “Create”
  11. Save generated API key file
  12. Rename file to api-key.json Make sure to move the key into speech-to-text cloned repo, if you plan to test this code.

3. Convert Audio File to Wav format

There are a lot of tools you may use to convert audio files.

4. Break up audio file into smaller parts

Google Cloud Speech API only accepts files no longer than 60 seconds. To be on the safe side, I broke my files in 30-second chunks. To do that I used an open source command line library called ffmpeg. I ran it on Windows, you can install ffmpeg using instruction from this site (https://www.wikihow.com/Install-FFmpeg-on-Windows) and then run in your command line (cmd.exe) below instruction:
Clean out old parts if needed via rm -rf parts/*
ffmpeg -i source/genevieve.wav -f segment -segment_time 30 -c copy parts/out%09d.wav

5. Install required Python modules

Install:
  1. google-api-python-client
  2. httplib2
  3. oauth2client
  4. pyasn1
  5. pyasn1-modules
  6. rsa
  7. six
  8. SpeechRecognition
  9. tqdm
  10. uritemplate

6. Run the Code

  1. Loads API key from step 2 in memory
  2. Gets a list of files (chunks)
  3. For every file, calls speech to text API endpoint
  4. Adds results to a list
  5. Saves results

Comments

Popular posts from this blog

AutoML-Papers

Awesome-AutoML-Papers A curated list of automated machine learning papers, articles, tutorials, slides and projects. Introduction to AutoML Machine learning (ML) has achieved considerable successes in recent years and an ever-growing number of disciplines rely on it. However, this success crucially relies on human machine learning experts to perform the following tasks: Preprocess the data Select appropriate features Select an appropriate model family Optimize model hyperparameters Postprocess machine learning models Critically analyze the results obtained. As the complexity of these tasks is often beyond non-ML-experts, the rapid growth of machine learning applications has created a demand for off-the-shelf machine learning methods that can be used easily and without expert knowledge. We call the resulting research area that targets progressive automation of machine learning  AutoML . AutoML draws on many disciplines of machine learning, prominently including ...

Python Machine Learning Notebooks (Tutorial style)

Python Machine Learning Notebooks (Tutorial style) Dr. Tirthajyoti Sarkar, Sunnyvale, CA ( You can connect with me on LinkedIn here ) Essential codes/demo IPython notebooks for jump-starting machine learning/data science. You can start with this article that I wrote in Heartbeat magazine (on Medium platform): "Some Essential Hacks and Tricks for Machine Learning with Python" Essential tutorial-type notebooks on Pandas and Numpy Jupyter notebooks covering a wide range of functions and operations on the topics of NumPy, Pandans, Seaborn, matplotlib etc. Basics of Numpy array Basics of Pandas DataFrame Basics of Matplotlib and Descriptive Statistics Tutorial-type notebooks covering regression, classification, clustering, dimensionality reduction, and some basic neural network algorithms Regression Simple linear regression with t-statistic generation Multiple ways to do linear regression in Python and their speed comparison ( check the article I wr...

Deep Learning Project

An end to end tutorial of a machine learning pipeline This tutorial tries to do what most Most Machine Learning tutorials available online do not. It is not a 30 minute tutorial which teaches you how to "Train your own neural network" or "Learn deep learning in under 30 minutes". It's a full pipeline which you would need to do if you actually work with machine learning - introducing you to all the parts, and all the implementation decisions and details that need to be made. The dataset is not one of the standard sets like MNIST or CIFAR, you will make you very own dataset. Then you will go through a couple conventional machine learning algorithms, before finally getting to deep learning! In the fall of 2016, I was a Teaching Fellow (Harvard's version of TA) for the graduate class on "Advanced Topics in Data Science (CS209/109)" at Harvard University. I was in-charge of designing the class project given to the students, and this tutorial has...