|
| 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 | +import unittest |
| 16 | + |
| 17 | + |
| 18 | +class TestSpeechClient(unittest.TestCase): |
| 19 | + |
| 20 | + def test_sync_recognize_local_file(self): |
| 21 | + import io |
| 22 | + from google.cloud import speech |
| 23 | + client = speech.Client() |
| 24 | + file_name = 'system_tests/data/hello.wav' |
| 25 | + |
| 26 | + with io.open(file_name, 'rb') as file_obj: |
| 27 | + sample = client.sample(content=file_obj.read(), |
| 28 | + encoding=speech.Encoding.LINEAR16, |
| 29 | + sample_rate=16000) |
| 30 | + res = client.sync_recognize(sample, |
| 31 | + language_code='en-US', |
| 32 | + max_alternatives=2, |
| 33 | + profanity_filter=True, |
| 34 | + speech_context=['Google', 'cloud']) |
| 35 | + self.assertEqual(res[0].transcript, |
| 36 | + 'hello thank you for using Google Cloud platform') |
| 37 | + self.assertEqual(len(res), 2) |
| 38 | + |
| 39 | + def test_sync_recognize_gcs_file(self): |
| 40 | + from google.cloud import speech |
| 41 | + client = speech.Client() |
| 42 | + source_uri = 'gs://ferrous-arena-my-test-bucket/hello.wav' |
| 43 | + |
| 44 | + sample = client.sample(source_uri=source_uri, |
| 45 | + encoding=speech.Encoding.LINEAR16, |
| 46 | + sample_rate=16000) |
| 47 | + res = client.sync_recognize(sample, |
| 48 | + language_code='en-US', |
| 49 | + max_alternatives=1, |
| 50 | + profanity_filter=True, |
| 51 | + speech_context=['Google', 'cloud']) |
| 52 | + self.assertEqual(res[0].transcript, |
| 53 | + 'hello thank you for using Google Cloud platform') |
| 54 | + self.assertEqual(len(res), 1) |
0 commit comments