Skip to content

Latest commit

 

History

History
 
 

api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Speech API Samples

These samples show how to use the Google Cloud Speech API to transcribe audio files, using the Google API Client Library for .NET.

This sample requires .NET Core 2.0 or later. That means using Visual Studio 2017, or the command line. Visual Studio 2015 users can use this older sample.

You can also build, run and edit this sample in your web browser using Google Cloud Shell. The instructions on how to do this are in the Build and Run with Google Cloud Shell section below.

Build and Run

  1. Follow the set-up instructions in the documentation.

  2. Enable APIs for your project. Click here to visit Cloud Platform Console and enable the Google Cloud Speech API.

  3. From a Powershell command line, run the QuickStart sample:

    PS C:\...\dotnet-docs-samples\speech\api\QuickStart> dotnet restore
    PS C:\...\dotnet-docs-samples\speech\api\QuickStart> dotnet run
    how old is the Brooklyn Bridge
    
  4. And run Recognize for more examples:

    PS C:\...\dotnet-docs-samples\speech\api\Recognize> dotnet restore
    PS C:\...\dotnet-docs-samples\speech\api\Recognize> dotnet run
    Recognize 1.0.0
    Copyright (C) 2017 Recognize
    
    ERROR(S):
    No verb selected.
    
    sync            Detects speech in an audio file.
    
    async           Creates a job to detect speech in an audio file, and waits for the job to complete.
    
    stream          Detects speech in an audio file by streaming it to the Speech API.
    
    listen          Detects speech in a microphone input stream.
    
    rec             Detects speech in an audio file. Supports other file formats.
    
    sync-creds      Detects speech in an audio file.
    
    with-context    Detects speech in an audio file. Add additional context on stdin.
    
    help            Display more information on a specific command.
    
    version         Display version information.
    
    PS C:\...\dotnet-docs-samples\speech\api\Recognize> dotnet run listen 3
    Speak now.
    test
    testing
    testing one
    testing
     one
    testing
     one two
    testing one
     two
    testing
     1 2 3
    testing 1 2 3
    PS C:\...\dotnet-docs-samples\speech\api\Recognize>
    

Build and Run with Google Cloud Shell

  1. Follow the instructions in the root README.

  2. Enable APIs for your project. Click here to visit Cloud Platform Console and enable the Google Cloud Speech API.

  3. Open the sample with Cloud Shell.

  4. Upload your JSON key file to Cloud Shell:

    • Use the Cloud Shell file browser to select the dotnet-doc-samples folder.
    • Use the File menu to select Import > File or Zip Archive
    • Select and import the JSON key that was downloaded as instructed in the root README. Use the Cloud Shell file browser to Import > File
  5. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON key that was just imported. In Cloud Shell console, the command will look like this:

    :~/$ export GOOGLE_APPLICATION_CREDENTIALS=../../../your-project-id-dea9fa230eae3.json
    
  6. In Cloud Shell console, run the QuickStart sample:

    :~/dotnet-docs-samples/speech/api$ cd QuickStart
    :~/dotnet-docs-samples/speech/api/QuickStart$ dotnet run
    how old is the Brooklyn Bridge
    
  7. And run Recognize for more examples:

    :~/dotnet-docs-samples/speech/api/QuickStart$ cd ../Recognize
    :~/dotnet-docs-samples/speech/api/Recognize$ dotnet run
    Recognize 1.0.0
    Copyright (C) 2017 Recognize
    
    ERROR(S):
    No verb selected.
    
    sync            Detects speech in an audio file.
    
    async           Creates a job to detect speech in an audio file, and waits for the job to complete.
    
    stream          Detects speech in an audio file by streaming it to the Speech API.
    
    listen          Detects speech in a microphone input stream.
    
    rec             Detects speech in an audio file. Supports other file formats.
    
    sync-creds      Detects speech in an audio file.
    
    with-context    Detects speech in an audio file. Add additional context on stdin.
    
    help            Display more information on a specific command.
    
    version         Display version information.
    
    :~/dotnet-docs-samples/speech/api/Recognize$ dotnet run sync ../resources/audio2.raw
    the rain in Spain stays mainly on the plain
    

Contributing changes

Licensing

Testing