8000 docs: add generated snippets (#321) · googleapis/google-cloud-python@4801f1d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4801f1d

Browse files
docs: add generated snippets (#321)
* chore: use gapic-generator-python 0.63.2 docs: add generated snippets PiperOrigin-RevId: 427792504 Source-Link: googleapis/googleapis@55b9e1e Source-Link: googleapis/googleapis-gen@bf4e86b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYmY0ZTg2Yjc1M2Y0MmNiMGVkYjFmZDUxZmJlODQwZDdkYTBhMWNkZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 683c06e commit 4801f1d

File tree

40 files changed

+3746
-0
lines changed

40 files changed

+3746
-0
lines changed

google-cloud-speech/google/cloud/speech_v1/services/speech/async_client.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,33 @@ async def recognize(
220220
r"""Performs synchronous speech recognition: receive
221221
results after all audio has been sent and processed.
222222
223+
224+
.. code-block::
225+
226+
from google.cloud import speech_v1
227+
228+
def sample_recognize():
229+
# Create a client
230+
client = speech_v1.SpeechClient()
231+
232+
# Initialize request argument(s)
233+
config = speech_v1.RecognitionConfig()
234+
config.language_code = "language_code_value"
235+
236+
audio = speech_v1.RecognitionAudio()
237+
audio.content = b'content_blob'
238+
239+
request = speech_v1.RecognizeRequest(
240+
config=config,
241+
audio=audio,
242+
)
243+
244+
# Make the request
245+
response = client.recognize(request=request)
246+
247+
# Handle the response
248+
print(response)
249+
223250
Args:
224251
request (Union[google.cloud.speech_v1.types.RecognizeRequest, dict]):
225252
The request object. The top-level message sent by the
@@ -312,6 +339,37 @@ async def long_running_recognize(
312339
on asynchronous speech recognition, see the
313340
`how-to <https://cloud.google.com/speech-to-text/docs/async-recognize>`__.
314341
342+
343+
.. code-block::
344+
345+
from google.cloud import speech_v1
346+
347+
def sample_long_running_recognize():
348+
# Create a client
349+
client = speech_v1.SpeechClient()
350+
351+
# Initialize request argument(s)
352+
config = speech_v1.RecognitionConfig()
353+
config.language_code = "language_code_value"
354+
355+
audio = speech_v1.RecognitionAudio()
356+
audio.content = b'content_blob'
357+
358+
request = speech_v1.LongRunningRecognizeRequest(
359+
config=config,
360+
audio=audio,
361+
)
362+
363+
# Make the request
364+
operation = client.long_running_recognize(request=request)
365+
366+
print("Waiting for operation to complete...")
367+
368+
response = operation.result()
369+
370+
# Handle the response
371+
print(response)
372+
315373
Args:
316374
request (Union[google.cloud.speech_v1.types.LongRunningRecognizeRequest, dict]):
317375
The request object. The top-level message sent by the
@@ -402,6 +460,40 @@ def streaming_recognize(
402460
receive results while sending audio. This method is only
403461
available via the gRPC API (not REST).
404462
463+
464+
.. code-block::
465+
466+
from google.cloud import speech_v1
467+
468+
def sample_streaming_recognize():
469+
# Create a client
470+
client = speech_v1.SpeechClient()
471+
472+
# Initialize request argument(s)
473+
streaming_config = speech_v1.StreamingRecognitionConfig()
474+
streaming_config.config.language_code = "language_code_value"
475+
476+
request = speech_v1.StreamingRecognizeRequest(
477+
streaming_config=streaming_config,
478+
)
479+
480+
# This method expects an iterator which contains
481+
# 'speech_v1.StreamingRecognizeRequest' objects
482+
# Here we create a generator that yields a single `request` for
483+
# demonstrative purposes.
484+
requests = [request]
485+
486+
def request_generator():
487+
for request in requests:
488+
yield request
489+
490+
# Make the request
491+
stream = client.streaming_recognize(requests=request_generator())
492+
493+
# Handle the response
494+
for response in stream:
495+
print(response)
496+
405497
Args:
406498
requests (AsyncIterator[`google.cloud.speech_v1.types.StreamingRecognizeRequest`]):
407499
The request object AsyncIterator. The top-level message sent by the

google-cloud-speech/google/cloud/speech_v1/services/speech/client.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,34 @@ def recognize(
429429
r"""Performs synchronous speech recognition: receive
430430
results after all audio has been sent and processed.
431431
432+
433+
434+
.. code-block::
435+
436+
from google.cloud import speech_v1
437+
438+
def sample_recognize():
439+
# Create a client
440+
client = speech_v1.SpeechClient()
441+
442+
# Initialize request argument(s)
443+
config = speech_v1.RecognitionConfig()
444+
config.language_code = "language_code_value"
445+
446+
audio = speech_v1.RecognitionAudio()
447+
audio.content = b'content_blob'
448+
449+
request = speech_v1.RecognizeRequest(
450+
config=config,
451+
audio=audio,
452+
)
453+
454+
# Make the request
455+
response = client.recognize(request=request)
456+
457+
# Handle the response
458+
print(response)
459+
432460
Args:
433461
request (Union[google.cloud.speech_v1.types.RecognizeRequest, dict]):
434462
The request object. The top-level message sent by the
@@ -511,6 +539,38 @@ def long_running_recognize(
511539
on asynchronous speech recognition, see the
512540
`how-to <https://cloud.google.com/speech-to-text/docs/async-recognize>`__.
513541
542+
543+
544+
.. code-block::
545+
546+
from google.cloud import speech_v1
547+
548+
def sample_long_running_recognize():
549+
# Create a client
550+
client = speech_v1.SpeechClient()
551+
552+
# Initialize request argument(s)
553+
config = speech_v1.RecognitionConfig()
554+
config.language_code = "language_code_value"
555+
556+
audio = speech_v1.RecognitionAudio()
557+
audio.content = b'content_blob'
558+
559+
request = speech_v1.LongRunningRecognizeRequest(
560+
config=config,
561+
audio=audio,
562+
)
563+
564+
# Make the request
565+
operation = client.long_running_recognize(request=request)
566+
567+
print("Waiting for operation to complete...")
568+
569+
response = operation.result()
570+
571+
# Handle the response
572+
print(response)
573+
514574
Args:
515575
request (Union[google.cloud.speech_v1.types.LongRunningRecognizeRequest, dict]):
516576
The request object. The top-level message sent by the
@@ -601,6 +661,41 @@ def streaming_recognize(
601661
receive results while sending audio. This method is only
602662
available via the gRPC API (not REST).
603663
664+
665+
666+
.. code-block::
667+
668+
from google.cloud import speech_v1
669+
670+
def sample_streaming_recognize():
671+
# Create a client
672+
client = speech_v1.SpeechClient()
673+
674+
# Initialize request argument(s)
675+
streaming_config = speech_v1.StreamingRecognitionConfig()
676+
streaming_config.config.language_code = "language_code_value"
677+
678+
request = speech_v1.StreamingRecognizeRequest(
679+
streaming_config=streaming_config,
680+
)
681+
682+
# This method expects an iterator which contains
683+
# 'speech_v1.StreamingRecognizeRequest' objects
684+
# Here we create a generator that yields a single `request` for
685+
# demonstrative purposes.
686+
requests = [request]
687+
688+
def request_generator():
689+
for request in requests:
690+
yield request
691+
692+
# Make the request
693+
stream = client.streaming_recognize(requests=request_generator())
694+
695+
# Handle the response
696+
for response in stream:
697+
print(response)
698+
604699
Args:
605700
requests (Iterator[google.cloud.speech_v1.types.StreamingRecognizeRequest]):
606701
The request object iterator. The top-level message sent by the

0 commit comments

Comments
 (0)
0