|
| 1 | +# Copyright 2016 Google, Inc |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +def run_quickstart |
| 16 | + # [START speech_quickstart] |
| 17 | + # Imports the Google Cloud client library |
| 18 | + require "google/cloud" |
| 19 | + |
| 20 | + # Your Google Cloud Platform project ID |
| 21 | + project_id = "YOUR_PROJECT_ID" |
| 22 | + |
| 23 | + # Instantiates a client |
| 24 | + gcloud = Google::Cloud.new project_id |
| 25 | + speech_client = gcloud.speech |
| 26 | + |
| 27 | + # The name of the audio file to transcribe |
| 28 | + fileName = "./audio_files/audio.raw" |
| 29 | + |
| 30 | + # The audio file's encoding and sample rate |
| 31 | + audio = speech_client.audio fileName, |
| 32 | + encoding: :raw, sample_rate: 16000 |
| 33 | + |
| 34 | + # Detects speech in the audio file |
| 35 | + results = audio.recognize |
| 36 | + result = results.first |
| 37 | + |
| 38 | + puts "Transcription: #{result.transcript}" |
| 39 | + # [END speech_quickstart] |
| 40 | +end |
| 41 | + |
| 42 | +if __FILE__ == $PROGRAM_NAME |
| 43 | + run_quickstart |
| 44 | +end |
0 commit comments