Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!

Prior explanation

Latest information (November 7, 2017)

It seems that the googleAPI interface has been changed and it does not work as it is. If you are new to stream speech recognition in the future, please refer to the following article by @delete. https://qiita.com/delete/items/395776c6843d67fd65fd

Articles I wrote earlier

It is below.

I want to perform stream speech recognition using the Google Cloud Speech gRPC API! (With a simple VAD)] http://qiita.com/sayonari/items/a70118a468483967ad34

Explanation of this article

This article does not work well when I did google voice recognition in the new environment, so I will leave a note when I installed it from the beginning. We have not been able to re-verify it properly, so if you find any opinions or corrections, please feel free to give us your opinions.

Main story

Execution environment

--Machine: MacBook Pro (Retina, 13-inch, Early 2015)

Installation

google cloud API dashboard https://console.cloud.google.com/?hl=ja The method of making the speech API available with the google cloud API is quite annoying, but there is a lot of information, so please google it yourself.

Creating a project

Create a project with your favorite name. I made a project called GoogleCloudAPI-ASRtest. If you can use SpeechAPI, the ID in the API will be displayed, so remember it.

Library installation

pip install google.cloud.speech

Install gcloud command

https://cloud.google.com/sdk/docs/quickstart-mac-os-x?hl=ja

Run ʻinstall.sh`

SDK initialization

gcloud init

You will be asked "You must log in to continue. Would you like to log in (Y / n)?", So enter Y.

The browser will start up, so log in with the google account registered with the API.

Under "Pick cloud project to use:", the API project name is listed along with the number, so select the project in which SpeechAPI is registered.

「Do you want to configure Google Compute Engine (https://cloud.google.com/compute) settings (Y / n)? ”Select the server as Y. It was changed to "[2] asia-east1-b".

Add the path to PYTHONPATH

pip install gcloud

Add the installed directory to PYTHONPATH

In my case, it was as follows. export PYTHONPATH="/Users/nishimura/.pyenv/versions/3.6.1/lib/python3.6/site-packages:$PYTHONPATH"

If you add this to ~ / .bash_profile, it will be executed automatically every time, which is convenient.

Credential default settings

gcloud auth application-default login

The browser will start up, so log in with your google account. Application approval.

Run google sample

https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/speech/cloud-client

If you execute transcribe_streaming_mic.py, you can recognize the voice in English.

I want to recognize Japanese voice!

Specify directly in the program (in the main function) where config is set.

language_code='ja-JP'

I want to give recognition candidates (phrase hints)!

Why not rewrite the config in the main function like this?

    config = types.RecognitionConfig(
        encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
        sample_rate_hertz=RATE,
        language_code='ja-JP',
        speech_contexts=[speech.types.SpeechContext(
            phrasesHints=["Kita has come","Really"]
        )]
    )

However, since "reading" is not given, it is not recognized well when written in kanji. Sorry. If anyone knows "how to give reading", please let me know m (_ _) m

Referenced pages not mentioned above

Official manual https://media.readthedocs.org/pdf/google-cloud-python/latest/google-cloud-python.pdf

Recommended Posts

Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!
Speech transcription procedure using Python and Google Cloud Speech API
Speech file recognition by Google Speech API v2 using Python
Streaming speech recognition with Google Cloud Speech API
Speech transcription procedure using Google Cloud Speech API
Speech recognition of wav files with Google Cloud Speech API Beta
[Python3] Google translate google translate without using api
I tried using docomo speech recognition API and Google Speech API in Java
Google Cloud Speech API vs. Amazon Transcribe
Google Cloud Vision API sample for python
Try using Python with Google Cloud Functions
Use Google Cloud Vision API from Python
Video processing using Python + OpenCV on Mac
Creating Google Spreadsheet using Python / Google Data API
python on mac
Automatic voice transcription with Google Cloud Speech API
I tried using the Google Cloud Vision API
Tweet (API 1.1) on Google App Engine for Python
Output repository list using Github API on Mac
[Google Cloud Platform] Use Google Cloud API using API Client Library
[GCP] [Python] Deploy API serverless with Google Cloud Functions!
Upload JPG file using Google Drive API in Python
Install Python on Mac
Install Python 3 on Mac
From python to running instance on google cloud platform
[Python] Get insight data using Google My Business API
Speech recognition in Python
Build a Python environment on your Mac using pyenv
Install Python 3.4 on Mac
Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)
Using NAOqi 2.4.2 Python SDK on Mac OS X El Capitan
Build an Ubuntu python development environment on Google Cloud Platform
Building a Python environment on a Mac and using Jupyter lab
Access google spreadsheet using python on raspberry pi (for myself)
A note on touching Microsoft's face recognition API in Python
Try to determine food photos using Google Cloud Vision API
Let's publish the super resolution API using Google Cloud Platform
Easy on Mac! Plot of unit step response using Python
Play with YouTube Data API v3 using Google API Python Client
Speech recognition by Python MFCC
Install pygame on python3.4 on mac
Age recognition using Pepper's API
Handling of python on mac
Update python on Mac to 3.7-> 3.8
Install pandas 0.14 on python3.4 [on Mac]
Notes on installing Python on Mac
Broadcast on LINE using python
Google Drive Api Tips (Python)
Using OpenCV with Python @Mac
Build a game leaderboard on Alibaba cloud using Python and Redis
Ansible playbook for setting up Python preferences using pyenv on Mac
Regularly upload files to Google Drive using the Google Drive API in Python
[SEO] Flow / sample code when using Google Analytics API in Python
[Ruby on Rails] Display and pinning of GoolgeMAP using Google API
Building a Python environment on Mac
Print PDF using Google Cloud Print. (GoogleAPI)
If python on mac goes missing
Data acquisition using python googlemap api
[Python] Hit the Google Translation API
Notes on using MeCab from Python