Prerequisites
- Complete all required steps in the before you begin quickstart.
- Deploy the API .
- Query the API to make sure it's working.
Install dependencies
-
Clone
python-speechand change the directory to the sample directory.$ git clone https://github.com/googleapis/python-speech.git $ cd python-speech/samples/snippets -
Install pip and virtualenv if you have not already done so. Refer to the Google Cloud Platform Python Development Environment Setup Guide for more information.
-
Create a
virtualenv. The samples below are compatible with Python 2.7 and 3.4+.$ virtualenv env $ source env/bin/activate -
Install the dependencies needed to run the samples.
$ pip install -r requirements.txt
Code sample
The code sample below uses the google-cloud-speech library . You can use GitHub to browse the source and report issues .
Transcribe an audio file
You can use the code sample below to transcribe an audio file using either a public IP or cluster level IP. For more information on IP types, see the documentation on querying the API .
Public IP:
#
Using
a
Public
IP
$
python
transcribe_onprem.py
--file_path="../resources/two_channel_16k.wav"
--api_endpoint= ${
PUBLIC_IP
}
:443
Cluster level IP:
# Using a cluster level IP
$ kubectl port-forward -n $NAMESPACE $POD 10000:10000
$ python transcribe_onprem.py --file_path="../resources/two_channel_16k.wav" --api_endpoint="0.0.0.0:10000"
Python
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

