快速入门:在 Windows、Linux 或 Android 上运行语音设备 SDK 示例应用Quickstart: Run the Speech Devices SDK sample app on Windows, Linux or Android
重要
需要语音 SDK 1.11.0 或更高版本。Speech SDK version 1.11.0 or later is required.
本快速入门介绍如何使用适用于 Windows 的语音设备 SDK 来生成支持语音的产品。In this quickstart, you'll learn how to use the Speech Devices SDK for Windows to build a speech-enabled product.
该应用程序是使用语音 SDK 程序包和 Eclipse Java IDE (v4) 在 64 位 Windows 上构建的。The application is built with the Speech SDK package, and the Eclipse Java IDE (v4) on 64-bit Windows. 它在 64 位 Java 8 运行时环境 (JRE) 中运行。It runs on a 64-bit Java 8 runtime environment (JRE).
本指南需要一个包含语音服务资源的 Azure 认知服务帐户。This guide requires an Azure Cognitive Services account with a Speech service resource.
示例应用程序的源代码随附在语音设备 SDK 中,The source code for the sample application is included with the Speech Devices SDK. 也可在 GitHub 上获取。It's also available on GitHub.
先决条件Prerequisites
本快速入门需要:This quickstart requires:
- 操作系统:64 位 WindowsOperating System: 64-bit Windows
- 麦克风阵列,如 Azure Kinect DKA microphone array such as Azure Kinect DK
- Eclipse Java IDEEclipse Java IDE
- 仅限 Java 8 或 JDK 8。Java 8 or JDK 8 only.
- Microsoft Visual C++ RedistributableMicrosoft Visual C++ Redistributable
- 语音服务的 Azure 订阅密钥。An Azure subscription key for the Speech service. 免费获得一个。Get one for free.
- 下载用于 Java 的语音设备 SDK 的最新版本,并将 .zip 提取到工作目录。Download the latest version of the Speech Devices SDK for Java, and extract the .zip to your working directory.
备注
本快速入门假设应用已解压缩到 C:\SDSDK\JRE-Sample-ReleaseThis quickstart assumes that the app is extracted to C:\SDSDK\JRE-Sample-Release
如果计划使用意向,则将需要语音理解服务 (LUIS) 订阅。If you plan to use the intents you'll need a Language Understanding Service (LUIS) subscription. 若要了解有关 LUIS 和意向识别的详细信息,请参阅使用 LUIS、C# 识别语音意向。To learn more about LUIS and intent recognition, see Recognize speech intents with LUIS, C#. 示例 LUIS 模型适用于此应用。A sample LUIS model is available for this app.
创建和配置项目Create and configure the project
启动 Eclipse。Start Eclipse.
在 Eclipse IDE Launcher 的“工作区”字段中,输入新工作区目录的名称 。In the Eclipse IDE Launcher, in the Workspace field, enter the name of a new workspace directory. 然后选择“启动”。Then select Launch.
片刻之后,Eclipse IDE 的主窗口将会显示。In a moment, the main window of the Eclipse IDE appears. 如果出现了欢迎屏幕,请将其关闭。Close the Welcome screen if one is present.
从 Eclipse 菜单栏上,依次选择“文件” > “新建” > “Java 项目”以新建一个项目。From the Eclipse menu bar, create a new project by choosing File > New > Java Project. 如果不可用,请依次选择“项目”和“Java 项目”。If not available choose Project and then Java Project.
此时将启动“新建 Java 项目”向导。The New Java Project wizard starts. 浏览 示例项目所在的位置。Browse for the location of the sample project. 选择“完成” 。Select Finish.
在“包资源管理器”中,右键单击你的项目。In the Package explorer, right-click your project. 从上下文菜单中选择“配置” > “转换为 Maven 项目”。Choose Configure > Convert to Maven Project from the context menu. 选择“完成”。Select Finish.
打开 pom.xml 文件并对其进行编辑。Open the pom.xml file and edit it.
在文件末尾,在结束标记
</project>
之前,创建repositories
和dependencies
元素(如此处所示),并确保version
与当前版本匹配:At the end of the file, before the closing tag</project>
, createrepositories
anddependencies
elements, as shown here, and ensure theversion
matches your current version:<repositories> <repository> <id>maven-cognitiveservices-speech</id> <name>Microsoft Cognitive Services Speech Maven Repository</name> <url>https://csspeechstorage.blob.core.windows.net/maven/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.microsoft.cognitiveservices.speech</groupId> <artifactId>client-sdk</artifactId> <version>1.15.0</version> </dependency> </dependencies>
将 Windows-x64 的内容复制到 Java 项目位置,如 C:\SDSDK\JRE-Sample-ReleaseCopy the contents of Windows-x64 to the Java Project location, eg C:\SDSDK\JRE-Sample-Release
将
kws.table
、participants.properties
、Microsoft.CognitiveServices.Speech.extension.pma.dll
复制到项目文件夹 target\classesCopykws.table
,participants.properties
andMicrosoft.CognitiveServices.Speech.extension.pma.dll
into the project folder target\classes
配置示例应用程序Configure the sample application
将语音订阅密钥添加到源代码。Add your speech subscription key to the source code. 如果想要尝试意向识别,还需要添加语言理解服务订阅密钥和应用程序 ID。If you want to try intent recognition, also add your Language Understanding service subscription key and application ID.
对于语音和 LUIS,你的信息将进入
FunctionsList.java
:For speech and LUIS, your information goes intoFunctionsList.java
:// Subscription private static String SpeechSubscriptionKey = "<enter your subscription info here>"; private static String SpeechRegion = "chinaeast2"; // You can change this if your speech region is different. private static String LuisSubscriptionKey = "<enter your subscription info here>"; private static String LuisRegion = "chinaeast2"; // you can change this, if you want to test the intent, and your LUIS region is different. private static String LuisAppId = "<enter your LUIS AppId>";
默认关键字为“Computer”。The default keyword (keyword) is "Computer". 还可以尝试所提供的其他关键字之一,例如“Machine”或“Assistant”。You can also try one of the other provided keywords, like "Machine" or "Assistant". 这些备用关键字的资源文件位于语音设备 SDK 的 keyword 文件夹中。The resource files for these alternate keywords are in the Speech Devices SDK, in the keyword folder. 例如,
C:\SDSDK\JRE-Sample-Release\keyword\Computer
包含用于关键字“Computer”的文件。For example,C:\SDSDK\JRE-Sample-Release\keyword\Computer
contains the files used for the keyword "Computer".要使用新的关键字,请更新
FunctionsList.java
中的下面一行,并将关键字复制到应用。To use a new keyword, update the following line inFunctionsList.java
, and copy the keyword to your app. 例如,要使用关键字包machine.zip
中的关键字“Machine”,请执行以下操作:For example, to use the keyword 'Machine' from the keyword packagemachine.zip
:将
kws.table
文件从 zip 包复制到项目文件夹“target/classes”中。Copy thekws.table
file from the zip package into the project folder target/classes.使用关键字名称更新
FunctionsList.java
:Update theFunctionsList.java
with the keyword name:private static final String Keyword = "Machine";
从 Eclipse 运行示例应用程序Run the sample application from Eclipse
从 Eclipse 菜单栏中,依次选择“运行” > “运行方式” > “Java 应用程序”。From the Eclipse menu bar, Run > Run As > Java Application. 然后选择“FunctionsList”和“确定”。Then select FunctionsList and OK.
语音设备 SDK 示例应用程序将会启动,并显示以下选项:The Speech Devices SDK example application starts and displays the following options:
创建并运行独立应用程序Create and run a standalone application
在“包资源管理器”中,右键单击你的项目。In the Package explorer, right-click your project. 选择“导出”。Choose Export.
此时将显示“导出”窗口。The Export window appears. 展开“Java”,选择“可运行的 JAR 文件”,然后选择“下一步”。Expand Java and select Runnable JAR file and then select Next.
此时将显示“可运行的 JAR 文件导出”窗口。The Runnable JAR File Export window appears. 为应用程序选择“导出目标”,然后选择“完成”。Choose an Export destination for the application, and then select Finish.
请将
kws.table
、participants.properties
、unimic_runtime.dll
、pma.dll
和Microsoft.CognitiveServices.Speech.extension.pma.dll
放入上面选择的目标文件夹中,因为该应用程序需要这些文件。Please putkws.table
,participants.properties
,unimic_runtime.dll
,pma.dll
andMicrosoft.CognitiveServices.Speech.extension.pma.dll
in the destination folder chosen above as these files are needed by the application.运行独立的应用程序To run the standalone application
java -jar SpeechDemo.jar
本快速入门介绍如何使用适用于 Linux 的语音设备 SDK 来生成支持语音的产品。In this quickstart, you'll learn how to use the Speech Devices SDK for Linux to build a speech-enabled product.
该应用程序是使用语音 SDK 程序包和 Eclipse Java IDE (v4) 在 64 位 Linux(Ubuntu 16.04、Ubuntu 18.04、Debian 9、RHEL 7/8、CentOS 7/8)上构建的。The application is built with the Speech SDK package, and the Eclipse Java IDE (v4) on 64-bit Linux (Ubuntu 16.04, Ubuntu 18.04, Debian 9, RHEL 7/8, CentOS 7/8). 它在 64 位 Java 8 运行时环境 (JRE) 中运行。It runs on a 64-bit Java 8 runtime environment (JRE).
本指南需要一个包含语音服务资源的 Azure 认知服务帐户。This guide requires an Azure Cognitive Services account with a Speech service resource.
示例应用程序的源代码随附在语音设备 SDK 中,The source code for the sample application is included with the Speech Devices SDK. 也可在 GitHub 上获取。It's also available on GitHub.
先决条件Prerequisites
本快速入门需要:This quickstart requires:
- 操作系统:64 位 Linux(Ubuntu 16.04、Ubuntu 18.04、Debian 9、RHEL 7/8、CentOS 7/8)Operating System: 64-bit Linux (Ubuntu 16.04, Ubuntu 18.04, Debian 9, RHEL 7/8, CentOS 7/8)
- Azure Kinect DKAzure Kinect DK
- Eclipse Java IDEEclipse Java IDE
- 仅限 Java 8 或 JDK 8。Java 8 or JDK 8 only.
- 语音服务的 Azure 订阅密钥。An Azure subscription key for the Speech service. 免费获得一个。Get one for free.
- 下载用于 Java 的语音设备 SDK 的最新版本,并将 .zip 提取到工作目录。Download the latest version of the Speech Devices SDK for Java, and extract the .zip to your working directory.
备注
本快速入门假设应用已解压缩到 /home/wcaltest/JRE-Sample-ReleaseThis quickstart assumes that the app is extracted to /home/wcaltest/JRE-Sample-Release
确保在启动 Eclipse 之前安装这些依赖项。Make sure these dependencies are installed before starting Eclipse.
在 Ubuntu 上:On Ubuntu:
sudo apt-get update sudo apt-get install libssl1.0.0 libasound2
在 Debian 9 上:On Debian 9:
sudo apt-get update sudo apt-get install libssl1.0.2 libasound2
在 RHEL/CentOS 上:On RHEL/CentOS:
sudo yum update sudo yum install alsa-lib openssl
备注
- 在 RHEL/CentOS 7 上,按照如何为语音 SDK 配置 RHEL/CentOS 7 上的说明进行操作。On RHEL/CentOS 7, follow the instructions on how to configure RHEL/CentOS 7 for Speech SDK.
- 在 RHEL/CentOS 8 上,按照如何配置 OpenSSL for Linux 上的说明进行操作。On RHEL/CentOS 8, follow the instructions on how to configure OpenSSL for Linux.
如果计划使用意向,则将需要语音理解服务 (LUIS) 订阅。If you plan to use the intents you'll need a Language Understanding Service (LUIS) subscription. 若要了解有关 LUIS 和意向识别的详细信息,请参阅使用 LUIS、C# 识别语音意向。To learn more about LUIS and intent recognition, see Recognize speech intents with LUIS, C#. 示例 LUIS 模型适用于此应用。A sample LUIS model is available for this app.
创建和配置项目Create and configure the project
启动 Eclipse。Start Eclipse.
在 Eclipse IDE Launcher 的“工作区”字段中,输入新工作区目录的名称 。In the Eclipse IDE Launcher, in the Workspace field, enter the name of a new workspace directory. 然后选择“启动”。Then select Launch.
片刻之后,Eclipse IDE 的主窗口将会显示。In a moment, the main window of the Eclipse IDE appears. 如果出现了欢迎屏幕,请将其关闭。Close the Welcome screen if one is present.
从 Eclipse 菜单栏上,依次选择“文件” > “新建” > “Java 项目”以新建一个项目。From the Eclipse menu bar, create a new project by choosing File > New > Java Project. 如果不可用,请依次选择“项目”和“Java 项目”。If not available choose Project and then Java Project.
此时将启动“新建 Java 项目”向导。The New Java Project wizard starts. 浏览 示例项目所在的位置。Browse for the location of the sample project. 选择“完成”。Select Finish.
在“包资源管理器”中,右键单击你的项目。In the Package explorer, right-click your project. 从上下文菜单中选择“配置” > “转换为 Maven 项目”。Choose Configure > Convert to Maven Project from the context menu. 选择“完成”。Select Finish.
打开 pom.xml 文件并对其进行编辑。Open the pom.xml file and edit it.
在文件末尾,在结束标记
</project>
之前,创建repositories
和dependencies
元素(如此处所示),并确保version
与当前版本匹配:At the end of the file, before the closing tag</project>
, createrepositories
anddependencies
elements, as shown here, and ensure theversion
matches your current version:<repositories> <repository> <id>maven-cognitiveservices-speech</id> <name>Microsoft Cognitive Services Speech Maven Repository</name> <url>https://csspeechstorage.blob.core.windows.net/maven/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.microsoft.cognitiveservices.speech</groupId> <artifactId>client-sdk</artifactId> <version>1.15.0</version> </dependency> </dependencies>
在“包资源管理器”中,右键单击你的项目。In the Package explorer, right-click your project. 选择“属性”,然后依次选择“运行/调试设置” > “新建...”Choose Properties, then Run/Debug Settings > New… > Java 应用程序。 > Java Application.
此时将显示“编辑配置”窗口。The Edit Configuration window appears. 在“名称”字段中,输入 Main,并对“Main 类”使用“搜索” ,以查找和选择 com.microsoft.cognitiveservices.speech.samples.FunctionsList。In the Name field enter Main, and use Search for the Main Class to find and select com.microsoft.cognitiveservices.speech.samples.FunctionsList.
从 Linux-arm 或 Linux-x64 中将目标体系结构的音频二进制文件复制到 Java 项目位置,例如 /home/wcaltest/JRE-Sample-ReleaseCopy the audio binaries for your target architecture, from either Linux-arm or Linux-x64, to the Java Project location, eg /home/wcaltest/JRE-Sample-Release
同样从“编辑配置”窗口中,选择“环境”页和“新建”。Also from the Edit Configuration window select the Environment page and New. 此时将显示“新环境变量”窗口。The New Environment Variable window appears. 在“名称”字段中输入 LD_LIBRARY_PATH,并在“值”字段中输入包含 *.so 文件的文件夹,例如 /home/wcaltest/JRE-Sample-ReleaseIn the Name field enter LD_LIBRARY_PATH and in the value field enter the folder containing the *.so files, for example /home/wcaltest/JRE-Sample-Release
将
kws.table
和participants.properties
复制到项目文件夹 target/classesCopykws.table
andparticipants.properties
into the project folder target/classes
配置示例应用程序Configure the sample application
将语音订阅密钥添加到源代码。Add your speech subscription key to the source code. 如果想要尝试意向识别,还需要添加语言理解服务订阅密钥和应用程序 ID。If you want to try intent recognition, also add your Language Understanding service subscription key and application ID.
对于语音和 LUIS,你的信息将进入
FunctionsList.java
:For speech and LUIS, your information goes intoFunctionsList.java
:// Subscription private static String SpeechSubscriptionKey = "<enter your subscription info here>"; private static String SpeechRegion = "chinaeast2"; // You can change this if your speech region is different. private static String LuisSubscriptionKey = "<enter your subscription info here>"; private static String LuisRegion = "chinaeast2"; // you can change this, if you want to test the intent, and your LUIS region is different. private static String LuisAppId = "<enter your LUIS AppId>";
默认关键字为“Computer”。The default keyword (keyword) is "Computer". 还可以尝试所提供的其他关键字之一,例如“Machine”或“Assistant”。You can also try one of the other provided keywords, like "Machine" or "Assistant". 这些备用关键字的资源文件位于语音设备 SDK 的 keyword 文件夹中。The resource files for these alternate keywords are in the Speech Devices SDK, in the keyword folder. 例如,
/home/wcaltest/JRE-Sample-Release/keyword/Computer
包含用于关键字“Computer”的文件。For example,/home/wcaltest/JRE-Sample-Release/keyword/Computer
contains the files used for the keyword "Computer".要使用新的关键字,请更新
FunctionsList.java
中的下面一行,并将关键字复制到应用。To use a new keyword, update the following line inFunctionsList.java
, and copy the keyword to your app. 例如,要使用关键字包machine.zip
中的关键字“Machine”,请执行以下操作:For example, to use the keyword 'Machine' from the keyword packagemachine.zip
:将
kws.table
文件从 zip 包复制到项目文件夹“target/classes”中。Copy thekws.table
file from the zip package into the project folder target/classes.使用关键字名称更新
FunctionsList.java
:Update theFunctionsList.java
with the keyword name:private static final String Keyword = "Machine";
从 Eclipse 运行示例应用程序Run the sample application from Eclipse
从 Eclipse 菜单栏中,依次选择“运行” > “运行”From the Eclipse menu bar, Run > Run
语音设备 SDK 示例应用程序将会启动,并显示以下选项:The Speech Devices SDK example application starts and displays the following options:
创建并运行独立应用程序Create and run standalone the application
在“包资源管理器”中,右键单击你的项目。In the Package explorer, right-click your project. 选择“导出”。Choose Export.
此时将显示“导出”窗口。The Export window appears. 展开“Java”,选择“可运行的 JAR 文件”,然后选择“下一步”。Expand Java and select Runnable JAR file and then select Next.
此时将显示“可运行的 JAR 文件导出”窗口。The Runnable JAR File Export window appears. 为应用程序选择“导出目标”,然后选择“完成”。Choose an Export destination for the application, and then select Finish.
请将
kws.table
和participants.properties
放入上面选择的目标文件夹中,因为该应用程序需要这些文件。Please putkws.table
andparticipants.properties
in the destination folder chosen above as these files are needed by the application.将 LD_LIBRARY_LIB 设置为包含 *.so 文件的文件夹Set the LD_LIBRARY_LIB to the folder containing the *.so files
export LD_LIBRARY_PATH=/home/wcaltest/JRE-Sample-Release
运行独立的应用程序To run the standalone application
java -jar SpeechDemo.jar
本快速入门介绍如何使用适用于 Android 的语音设备 SDK 来生成支持语音的产品。In this quickstart, you'll learn how to use the Speech Devices SDK for Android to build a speech-enabled product.
本指南需要一个包含语音服务资源的 Azure 认知服务帐户。This guide requires an Azure Cognitive Services account with a Speech service resource.
示例应用程序的源代码随附在语音设备 SDK 中,The source code for the sample application is included with the Speech Devices SDK. 也可在 GitHub 上获取。It's also available on GitHub.
先决条件Prerequisites
开始使用语音设备 SDK 之前,需要:Before you start using the Speech Devices SDK, you'll need to:
按开发工具包中提供的说明启动设备。Follow the instructions provided with your development kit to power on the device.
下载语音设备 SDK 的最新版本,并将 .zip 提取到工作目录。Download the latest version of the Speech Devices SDK, and extract the .zip to your working directory.
备注
本快速入门假设应用已解压缩到 C:\SDSDK\Android-Sample-ReleaseThis quickstart assumes that the app is extracted to C:\SDSDK\Android-Sample-Release
获取语音服务的 Azure 订阅密钥To get an Azure subscription key for Speech service
如果计划使用语音服务来确定用户话语中的意向(或行动),则需语言理解服务 (LUIS) 订阅。If you plan to use the Speech service to identify intents (or actions) from user utterances, you'll need a Language Understanding Service (LUIS) subscription. 若要了解有关 LUIS 和意向识别的详细信息,请参阅使用 LUIS、C# 识别语音意向。To learn more about LUIS and intent recognition, see Recognize speech intents with LUIS, C#.
可创建一个简单的 LUIS 模型,或使用示例 LUIS 模型 LUIS-example.json。You can create a simple LUIS model or use the sample LUIS model, LUIS-example.json. 可从语音设备 SDK 下载站点获取示例 LUIS 模型。The sample LUIS model is available from the Speech Devices SDK download site. 选择“导入新应用”并选择 JSON 文件,将模型的 JSON 文件上传到 LUIS 门户。To upload your model's JSON file to the LUIS portal, select Import new app, and then select the JSON file.
在电脑上安装 Android Studio 和 Vysor。Install Android Studio and Vysor on your PC.
设置设备Set up the device
在计算机上启动 Vysor。Start Vysor on your computer.
你的设备应列在“选择设备”下。Your device should be listed under Choose a device. 选择设备旁边的“视图”按钮。Select the View button next to the device.
选择文件夹图标,然后选择“设置” > “WLAN”连接到无线网络。 Connect to your wireless network by selecting the folder icon, and then select Settings > WLAN.
备注
如果你的公司有关于将设备连接到 Wi-Fi 系统的政策,则你需要获取 MAC 地址并联系 IT 部门来了解如何将它连接到公司的 Wi-Fi。If your company has policies about connecting devices to its Wi-Fi system, you need to obtain the MAC address and contact your IT department about how to connect it to your company's Wi-Fi.
若要查找开发工具包的 MAC 地址,请在开发工具包的桌面上选择文件夹图标。To find the MAC address of the dev kit, select the file folder icon on the desktop of the dev kit.
选择“设置”。Select Settings. 搜索“mac 地址”,然后选择“Mac 地址” > “高级 WLAN”。 Search for "mac address", and then select Mac address > Advanced WLAN. 记下对话框底部附近显示的 MAC 地址。Write down the MAC address that appears near the bottom of the dialog box.
某些公司可能会限制设备可以连接到其 Wi-Fi 系统的时长。Some companies might have a time limit on how long a device can be connected to their Wi-Fi system. 在一定的天数后,可能需要延长开发工具包在 Wi-Fi 系统中的注册。You might need to extend the dev kit's registration with your Wi-Fi system after a specific number of days.
运行示例应用程序Run the sample application
若要验证开发工具包设置,请生成并安装示例应用程序:To validate your development kit setup, build and install the sample application:
启动 Android Studio。Start Android Studio.
选择“打开现有 Android Studio 项目”。Select Open an existing Android Studio project.
转到 C:\SDSDK\Android-Sample-Release\example。Go to C:\SDSDK\Android-Sample-Release\example. 选择“确定”打开示例项目。Select OK to open the example project.
配置 Gradle 以引用语音 SDK。Configure gradle to reference the Speech SDK. 可以在 Android Studio 的 Gradle Scripts 下找到以下文件。The following files can be found under Gradle Scripts in Android Studio.
通过添加 maven 行更新 build.gradle(Project:example) ,allprojects 块应该与下面匹配。Update the build.gradle(Project:example), the allprojects block should match below, by adding the maven lines.
allprojects { repositories { google() jcenter() mavenCentral() maven { url 'https://csspeechstorage.blob.core.windows.net/maven/' } } }
通过将以下行添加到 dependencies 节来更新 build.gradle(Module:app) 。Update the build.gradle(Module:app) by adding this line to the dependencies section.
implementation'com.microsoft.cognitiveservices.speech:client-sdk:1.15.0'
将语音订阅密钥添加到源代码。Add your speech subscription key to the source code. 如果想要尝试意向识别,还需要添加语言理解服务订阅密钥和应用程序 ID。If you want to try intent recognition, also add your Language Understanding service subscription key and application ID.
对于语音和 LUIS,你的信息会进入 MainActivity.java:For speech and LUIS, your information goes into MainActivity.java:
// Subscription private static String SpeechSubscriptionKey = "<enter your subscription info here>"; private static String SpeechRegion = "chinaeast2"; // You can change this if your speech region is different. private static String LuisSubscriptionKey = "<enter your subscription info here>"; private static String LuisRegion = "chinaeast2"; // you can change this, if you want to test the intent, and your LUIS region is different. private static String LuisAppId = "<enter your LUIS AppId>";
默认关键字为“Computer”。The default keyword is "Computer". 还可以尝试所提供的其他关键字之一,例如“Machine”或“Assistant”。You can also try one of the other provided keywords, like "Machine" or "Assistant". 这些备用关键字的资源文件位于语音设备 SDK 的 keyword 文件夹中。The resource files for these alternate keywords are in the Speech Devices SDK, in the keyword folder. 例如,C:\SDSDK\Android-Sample-Release\keyword\Computer 包含用于关键字“Computer”的文件。For example, C:\SDSDK\Android-Sample-Release\keyword\Computer contains the files used for the keyword "Computer".
要使用新的关键字,请更新
MainActivity.java
中的下面两行,并将关键字包复制到应用。To use a new keyword, update the following two lines inMainActivity.java
, and copy the keyword package to your app. 例如,若要使用关键字包 kws-machine.zip 中的关键字“Machine”,请执行以下操作:For example, to use the keyword 'Machine' from the keyword package kws-machine.zip:将该关键字包复制到“C:\SDSDK\Android-Sample-Release\example\app\src\main\assets"”文件夹中。Copy the keyword package into the folder "C:\SDSDK\Android-Sample-Release\example\app\src\main\assets".
使用关键字和包名称更新
MainActivity.java
:Update theMainActivity.java
with the keyword and the package name:private static final String Keyword = "Machine"; private static final String KeywordModel = "kws-machine.zip" // set your own keyword package name.
更新包含麦克风阵列几何设置的以下行:Update the following lines, which contain the microphone array geometry settings:
private static final String DeviceGeometry = "Circular6+1"; private static final String SelectedGeometry = "Circular6+1";
此表列出了支持的值:This table lists supported values:
变量Variable 含义Meaning 可用值Available values DeviceGeometry
物理麦克风配置Physical mic configuration 环形开发工具包: Circular6+1
For a circular dev kit:Circular6+1
线性开发工具包: Linear4
For a linear dev kit:Linear4
SelectedGeometry
软件麦克风配置Software mic configuration 使用所有麦克风的环形开发工具包: Circular6+1
For a circular dev kit that uses all mics:Circular6+1
使用四个麦克风的环形开发工具包: Circular3+1
For a circular dev kit that uses four mics:Circular3+1
使用所有麦克风的线性开发工具包: Linear4
For a linear dev kit that uses all mics:Linear4
使用两个麦克风的线性开发工具包: Linear2
For a linear dev kit that uses two mics:Linear2
若要生成应用程序,请在“运行”菜单中选择“运行‘应用’”。 To build the application, on the Run menu, select Run 'app'. 此时会显示“选择部署目标”对话框。The Select Deployment Target dialog box appears.
选择设备,然后选择“确定”,将应用程序部署到设备。Select your device, and then select OK to deploy the application to the device.
语音设备 SDK 示例应用程序将会启动,并显示以下选项:The Speech Devices SDK example application starts and displays the following options:
尽情体验吧!Experiment!
故障排除Troubleshooting
如果无法连接到语音设备。If you cannot connect to the Speech Device. 在命令提示符窗口中键入以下命令。Type the following command in a Command Prompt window. 这会返回设备列表:It will return a list of devices:
adb devices
备注
此命令使用 Android Debug Bridge adb.exe
,它是 Android Studio 安装的一部分。This command uses the Android Debug Bridge, adb.exe
, which is part of the Android Studio installation. 此工具位于 C:\Users[用户名]\AppData\Local\Android\Sdk\platform-tools 中。This tool is located in C:\Users[user name]\AppData\Local\Android\Sdk\platform-tools. 可将该目录添加到你的路径,以便更轻松地调用 adb
。You can add this directory to your path to make it more convenient to invoke adb
. 否则,必须在调用 adb
必须在每个调用 adb 的命令中指定到 adb.exe 的完整安装路径。Otherwise, you must specify the full path to your installation of adb.exe in every command that invokes adb
.
如果看到 no devices/emulators found
错误,请检查 USB 电缆是否已连接,并确保使用了高品质的电缆。If you see an error no devices/emulators found
then check your USB cable is connected and ensure a high quality cable is used.