Google Cloud Speech to Text 操作符

先决条件任务

要使用这些操作符,您必须执行以下几项操作

CloudSpeechToTextRecognizeSpeechOperator

识别音频输入中的语音并返回文本。

有关参数定义,请查看 CloudSpeechToTextRecognizeSpeechOperator

参数

config 和 audio 参数需要是 google.cloud.speech_v1.types 模块中对应类的字典或对象

有关更多信息,请参阅: https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/api.html#google.cloud.speech_v1.SpeechClient.recognize

tests/system/google/cloud/speech_to_text/example_speech_to_text.py[源代码]

INPUT = {"text": "Sample text for demo purposes"}
VOICE = {"language_code": "en-US", "ssml_gender": "FEMALE"}
AUDIO_CONFIG = {"audio_encoding": "LINEAR16"}

filename 是一个简单的字符串参数

tests/system/google/cloud/speech_to_text/example_speech_to_text.py[源代码]

CONFIG = RecognitionConfig({"encoding": "LINEAR16", "language_code": "en_US"})
AUDIO = RecognitionAudio({"uri": f"gs://{BUCKET_NAME}/{FILE_NAME}"})

使用操作符

tests/system/google/cloud/speech_to_text/example_speech_to_text.py[源代码]

speech_to_text_recognize_task = CloudSpeechToTextRecognizeSpeechOperator(
    config=CONFIG, audio=AUDIO, task_id="speech_to_text_recognize_task"
)

模板化

template_fields: Sequence[str] = (
    "audio",
    "config",
    "project_id",
    "gcp_conn_id",
    "timeout",
    "impersonation_chain",
)

参考

更多信息,请查看

此条目是否有帮助?