跳转到主要内容

Google Assistant API gRPC绑定

项目描述

此软件包包含为Python生成的Google Assistant Service绑定。它是Google Assistant SDK的一部分。

本软件包应与支持 gRPCPython 的 POSIX 平台兼容。

安装

  • 您可以使用 pip 进行安装。

    pip install --upgrade google-assistant-grpc

授权

用法

  • 使用 google.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc 初始化 gRPC 模型。

    import google.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc
    assistant = embedded_assistant_pb2.EmbeddedAssistantStub(channel)
  • 调用 Assist 流式方法。它接收一个 AssistRequest 生成器并返回一个 AssistResponse 生成器。

    assist_responses_generator = assistant.Assist(assist_requests_generator)
    start_acquiring_audio()
  • 发送带有音频配置参数的 AssistRequest 消息,然后发送多个包含助手请求音频数据的 AssistRequest 消息。

    import google.assistant.embedded.v1alpha1.embedded_assistant_pb2
    
    def generate_assist_requests():
        yield embedded_assistant_pb2.AssistConfig(
            audio_in_config=embedded_assistant_pb2.AudioInConfig(
                encoding='LINEAR16',
                sample_rate_hertz=16000,
            ),
            audio_out_config=embedded_assistant_pb2.AudioOutConfig(
                encoding='LINEAR16',
                sample_rate_hertz=16000,
            ),
            device_config=embedded_assistant_pb2.DeviceConfig(
                device_id=device_id,
                device_model_id=device_model_id,
            )
        )
        for data in acquire_audio_data():
            yield embedded_assistant_pb2.AssistRequest(audio_in=data)
  • 处理传入的 AssistResponse 流。

for assist_response in assist_response_generator:
    if resp.event_type == END_OF_UTTERANCE:
       stop_acquiring_audio()
    if resp.speech_results:
       print(' '.join(r.transcript for r in resp.speech_results)
    if resp.dialog_state_out.supplemental_display_text:
       print(resp.dialog_state_out.supplemental_display_text)
    if len(resp.audio_out.audio_data) > 0:
       playback_audio_data(resp.audio_out.audio_data)

参考

对于维护者

有关 Python 软件包的开发、维护和发布的更多文档,请参阅 MAINTAINER.md

许可证

版权(C)2017 Google Inc。

根据一个或多个贡献者许可协议许可给 Apache 软件基金会(ASF)。关于版权所有权的附加信息,请参阅与此工作一起分发的 NOTICE 文件。ASF 根据Apache许可证2.0(“许可证”)向您许可此文件;您只能根据许可证使用此文件。您可以在以下位置获得许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则根据本许可证分发的软件是以“现状”为基础分发的,不提供任何形式的明示或暗示保证。有关许可证中规定的权限和限制的具体语言,请参阅许可证。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

google-assistant-grpc-0.3.0.tar.gz (20.4 kB 查看散列值)

上传时间 源代码

构建分发

google_assistant_grpc-0.3.0-py2.py3-none-any.whl (21.2 kB 查看散列值)

上传时间 Python 2 Python 3

由以下组织支持