在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):androidthings/sample-googleassistant开源软件地址(OpenSource Url):https://github.com/androidthings/sample-googleassistant开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):Google Assistant SDK for devices - Android ThingsThis sample shows how to call the Google Assistant Service from Android Things using gRPC. It records a spoken request from the connected microphones, sends it to the Google Assistant API and plays back the Assistant's spoken response on the connected speaker.
Pre-requisites
Run the sample
google-oauthlib-tool --client-secrets client_secret_XXXX.json \
--credentials app/src/main/res/raw/credentials.json \
--scope https://www.googleapis.com/auth/assistant-sdk-prototype \
--save
./gradlew assembleDebug
adb install -g app/build/outputs/apk/debug/app-debug.apk
./gradlew installDebug
adb shell am start com.example.androidthings.assistant/.AssistantActivity
Audio ConfigurationBy default the sample routes audio to the I2S Voice Hat on Raspberry Pi 3 and default audio on other boards (on-board Line out or HDMI/USB if connected). You can change those mappings by changing the // Force using on-board Line out:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_BUILTIN_MIC);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
// Force using USB:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_USB_DEVICE);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_USB_DEVICE);
// Force using I2S:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_BUS);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUS); Device ActionsWith Device Actions, you can control hardware connected to your device. In this sample, you can turn on and off the LED attached to your Android Things board. Follow the guide here to learn how to register your device.
private static final String DEVICE_MODEL_ID = "my-device-model-id";
private static final String DEVICE_INSTANCE_ID = "my-device-instance-id";
mEmbeddedAssistant = new EmbeddedAssistant.Builder()
...
.setConversationCallback(new ConversationCallback() {
...
@Override
public void onDeviceAction(String intentName, JSONObject parameters) {
// Check the type of command
if (intentName.equals("action.devices.commands.OnOff")) {
try {
boolean turnOn = parameters.getBoolean("on");
mLed.setValue(turnOn);
} catch (JSONException e) {
Log.e(TAG, "Cannot get value of command", e);
} catch (IOException e) {
Log.e(TAG, "Cannot set value of LED", e);
}
}
}
}
...
... Try it:
The LED should change states based on your command. Enable auto-launch behaviorThis sample app is currently configured to launch only when deployed from your
development machine. To enable the main activity to launch automatically on boot,
add the following <activity ...>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity> LicenseCopyright 2017 The Android Open Source Project, 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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论