|
| 1 | +# Copyright 2022 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 | + |
| 16 | +# [START speech_create_recognizer] |
| 17 | +from google.cloud.speech_v2 import SpeechClient |
| 18 | +from google.cloud.speech_v2.types import cloud_speech |
| 19 | + |
| 20 | + |
| 21 | +def create_recognizer(project_id, recognizer_id): |
| 22 | + # Instantiates a client |
| 23 | + client = SpeechClient() |
| 24 | + |
| 25 | + request = cloud_speech.CreateRecognizerRequest( |
| 26 | + parent=f"projects/{project_id}/locations/global", |
| 27 | + recognizer_id=recognizer_id, |
| 28 | + recognizer=cloud_speech.Recognizer( |
| 29 | + language_codes=["en-US"], model="latest_long" |
| 30 | + ), |
| 31 | + ) |
| 32 | + |
| 33 | + operation = client.create_recognizer(request=request) |
| 34 | + recognizer = operation.result() |
| 35 | + |
| 36 | + print("Created Recognizer:", recognizer.name) |
| 37 | + return recognizer |
| 38 | + |
| 39 | + |
| 40 | +# [END speech_create_recognizer] |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + create_recognizer() |
0 commit comments