Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Last active April 1, 2019 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beccasaurus/52eacda5534fec8b963b897df0471178 to your computer and use it in GitHub Desktop.
Save beccasaurus/52eacda5534fec8b963b897df0471178 to your computer and use it in GitHub Desktop.
Code Sample with Declarative Test .yaml
samples:
- sample_id: transcribe_audio_file
description: Transcribe an audio file
type: SINGLE_RPC
api_method:
full_rpc: google.cloud.speech.v1.Speech.Recognize
api_request:
fields:
config:
encoding:
value: WAV
language_code:
description: The language of the supplied audio
value: en
enable_automatic_punctuation:
value: true
audio:
content:
input_type: LOCAL_FILE
description: "Path to local .wav file"
input_parameter: audio_file
response_handling:
code:
- comment: ["Print audio transcription {}", results]
- loop:
collection: $response.results
variable: result
body:
- comment: ["First alternative contains the most probable result"]
- define:
variable: most_probable_result
value: result.alternatives[0]
- print: ["Transcript: {}", most_probable_result.transcript]
- print: ["Confidence: {}", most_probable_result.confidence]
test_cases:
- name: Basic transcription from .wav (brooklyn.wav)
dependencies:
- type: gcs_resource_download
uri: gs://cloud-samples-data/speech/brooklyn.wav
inputs:
audio_file:
- "{}brooklyn_bridge.wav"
- $resource_directory
outputs:
- oneof:
-
- assert_contains_i: ["brooklyn"]
-
- assert_contains_i: ["bridge"]
- name: Basic transcription from .wav (commercial.wav)
dependencies:
- type: gcs_resource_download
uri: gs://cloud-samples-data/speech/commercial.wav
inputs:
audio_file:
- "{}brooklyn_bridge.wav"
- $resource_directory
outputs:
- oneof:
-
- assert_contains_i: ["chrome"]
-
- assert_contains_i: ["thank you"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment