Skip to main content

Google Assistant API gRPC bindings

Project description

This package contains the generated Python bindings for the Google Assistant gRPC API. It is part of the Google Assistant SDK.

This package should be compatible with POSIX platforms supporting gRPC and Python.

Installing

  • You can install using pip.:

    pip install --upgrade google-assistant-grpc

Authorization

  • Follow the steps to configure a Google API Console Project and a Google account to use with the Google Assistant SDK.

  • Download the client_secret_XXXXX.json file from the Google API Console Project credentials section and generate credentials using google-oauth-tool.:

    pip install --upgrade google-auth-oauthlib[tool]
    google-oauthlib-tool --client-secrets path/to/client_secret_XXXXX.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless
  • Load the credentials using google.oauth2.credentials.:

    import io
    import google.oauth2.credentials
    
    with io.open('/path/to/credentials.json', 'r') as f:
        credentials = google.oauth2.credentials.Credentials(token=None,
                                                            **json.load(f))
  • Initialize the gRPC channel using google.auth.transport.grpc.

Usage

  • Initialize the gRPC stubs using google.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc.:

    import google.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc
    assistant = embedded_assistant_pb2.EmbeddedAssistantStub(channel)
  • Call the Converse streaming method. It takes a generator of ConverseRequest and returns a generator of ConverseResponse.:

    converse_responses_generator = assistant.Converse(converse_requests_generator)
    start_acquiring_audio()
  • Send a ConverseRequest message with audio configuration parameters followed by multiple outgoing ConverseRequest messages containing the audio data of the Assistant request.:

    import google.assistant.embedded.v1alpha1.embedded_assistant_pb2
    
    def generate_converse_requests():
        yield embedded_assistant_pb2.ConverseConfig(
            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,
            ),
        )
        for data in acquire_audio_data():
            yield embedded_assistant_pb2.ConverseRequest(audio_in=data)
  • Handle the incoming stream of ConverseResponse messages:

for converse_response in converse_response_generator:
    if resp.event_type == END_OF_UTTERANCE:
       stop_acquiring_audio()
    if resp.result.spoken_request_text:
       print(resp.result.spoken_request_text)
    if len(resp.audio_out.audio_data) > 0:
       playback_audio_data(resp.audio_out.audio_data)

Reference

For Maintainers

See MAINTAINER.md for more documentation on the development, maintainance and release of the Python package itself.

License

Copyright (C) 2017 Google Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google-assistant-grpc-0.1.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

google_assistant_grpc-0.1.0-py2.py3-none-any.whl (19.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file google-assistant-grpc-0.1.0.tar.gz.

File metadata

File hashes

Hashes for google-assistant-grpc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4303606da6ac896df4efc46a0efab29f20fa5d82ae239002fee44cf1d746df2e
MD5 21153ffa702fa965c07a249df10fbe76
BLAKE2b-256 2877f35ed8365c8e43913e428a7de406c9e53495873e929b46bf6064470908c6

See more details on using hashes here.

Provenance

File details

Details for the file google_assistant_grpc-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for google_assistant_grpc-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 955d12d637cb16bedc3ee7d3d318f1e9d3143a24e863b7c8db599065ce527571
MD5 2977e824251dd51ef6bcef6fdc27333d
BLAKE2b-256 0c87dd76876d4312881a93f8827a8d7d81ed9a13daadf1f53a5fd4eca96d8412

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page