Package: google-assistant-grpc
This package contains the generatedPythonbindings for theGoogle Assistant Service.
It is part of theGoogle Assistant SDK.This package should be compatible with POSIX platforms supportinggRPCandPython.NoteThe Google Assistant Service is available fornon-commercial use.InstallingYou can install usingpip.:pip install --upgrade google-assistant-grpcAuthorizationFollow the steps toconfigure the Actions Console project and the Google account.Follow the steps toregister a new device model and download the client secrets file.Generate device credentials usinggoogle-oauthlib-tool:pip install –upgrade google-auth-oauthlib[tool]
google-oauthlib-tool –client-secrets path/to/client_secret_<client-id>.json –scopehttps://www.googleapis.com/auth/assistant-sdk-prototype–save –headlessLoad the device credentials usinggoogle.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 usinggoogle.auth.transport.grpc.UsageInitialize the gRPC stubs usinggoogle.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc.:import google.assistant.embedded.v1alpha1.embedded_assistant_pb2_grpc
assistant = embedded_assistant_pb2.EmbeddedAssistantStub(channel)Call theAssiststreaming method. It takes a generator ofAssistRequestand returns a generator ofAssistResponse.:assist_responses_generator = assistant.Assist(assist_requests_generator)
start_acquiring_audio()Send aAssistRequestmessage with audio configuration parameters followed by multiple outgoingAssistRequestmessages containing the audio data of the Assistant request.: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)Handle the incoming stream ofAssistResponsemessages:Stop recording when receiving aAssistResponsewith theEventTypemessage set toEND_OF_UTTERANCE.Get transcription of the user query from theSpeechRecognitionResultfield.Get conversation metadata like supplemental display text from the Assistant from theDialogStateOutfield.Extract the audio data of the Assistant response from theAudioOutfield.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)ReferencegRPC reference sample.Google Assistant Service reference.For MaintainersSeeMAINTAINER.mdfor more documentation on the
development, maintainance and release of the Python package itself.LicenseCopyright (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 athttp://www.apache.org/licenses/LICENSE-2.0Unless 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.