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
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:
Stop recording when receiving a ConverseResponse with the EventType message set to END_OF_UTTERANCE.
Get conversation metadata from the stream of ConverseResponse messages. (with the ConverseResult field set).
Extract the audio data of the Assistant response from the stream of ConverseResponse messages (with the AudioOut field set).
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for google-assistant-grpc-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a77a1bb227f01c5bc5f09b0b7d1622906c948aed33acd2e02fdc2e1fafebe14 |
|
MD5 | 43829ae3343eac75cf16f9d317a0de2c |
|
BLAKE2b-256 | 9f44cba2c429bf56943c4d1b05f87e52d1623555f0412bc9972aa5ece48abbc4 |
Hashes for google_assistant_grpc-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d4c4683e9c1e3eadf987bb42d928bc2441c93e886b5f8f92b6b54ad4f7dca1f |
|
MD5 | a88242b3b8a25c0cf0594fbc84f98208 |
|
BLAKE2b-256 | c0858fce6bb74d78a499a2909706944c462e6970e61ca43e534b4e3dd144c5cf |