先到百度语音官网上查看集成指南
然后再去下载语音识别-离在线融合SDK(bd_speech_sdk_asr_v3.0.3.20170801_60da871.zip)
直接参考SDK中的ActivityMiniRecog类
这里,我就直接上代码了,我是在Android Studio 2.3.3 平台上编译的
1、app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.sky.baiduspeechdemo"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(exclude: '*.bak', dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.code.gson:gson:2.8.2'
}
2、AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sky.baiduspeechdemo">
<!-- begin: baidu speech sdk 权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- end: baidu speech sdk 权限 -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- APP_ID API_KEY SECRET_KEY-->
<meta-data
android:name="com.baidu.speech.APP_ID"
android:value="替换成你申请的AppID"/>
<meta-data
android:name="com.baidu.speech.API_KEY"
android:value="替换成你申请的API Key" />
<meta-data
android:name="com.baidu.speech.SECRET_KEY"
android:value="替换成你申请的Secret Key" />
<service
android:name="com.baidu.speech.VoiceRecognitionService"
android:exported="false" />
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenLayout"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</