Skip to content

Commit

Permalink
登录拦截器优化、修复组件配置问题、加入语音识别功能组件
Browse files Browse the repository at this point in the history
wosojadfjgo committed Sep 4, 2019
1 parent 2908416 commit 534f946
Showing 130 changed files with 4,795 additions and 75 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# YouJu
[![](https://img.shields.io/badge/platform-android-brightgreen.svg)](https://developer.android.com/index.html) [![API](https://img.shields.io/badge/API-16%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=14) [![Twitter](https://img.shields.io/badge/Gradle-3.4.1-brightgreen.svg)](https://github.com/jiangzehui/polygonsview)


### 项目简介
“优聚”是一款集多个平台的资讯内容、复合型优秀资源和实用功能的APP,打破传统限制,融合多元,发现更多、更优秀、更有趣的东西。后续也会加入更多新的功能。也欢迎各位提出意见。
项目是一款组件化综合案例,包含新闻,MONO资讯,开眼视频,美女图片,垃圾分类,一言,古诗词,智能聊天机器人,语音识别功能,干货集中营,豆瓣电影等等模块。
项目利用业余时间开发,时间不固定,暂时只实现了这些功能。

### 主要模块
目前包含的主要模块有:base基础模块、network网络请求模块、语音识别模块、Gank模块、资讯模块。除base和network外,每个模块都可单独抽离为APP运行,不影响主工程,具体参照config.gradle配置文件。

### 架构模式
项目采用组件化Arouter+MVP+RxJava2+Retrofit2+AndroidX+Dagger2+Kotlin/Java混编模式

### \*\*
此项目属于业余时间练手的项目,接口数据来源均来自网络,如果存在侵权情况,请第一时间告知。本项目仅做学习交流使用,API数据内容所有权归原作公司所有,请勿用于其他用途!!

### Demo
[下载 Demo](https://github.com/HeYongRui/YouJu/tree/master/apk/app-debug.apk)体验

### 截图
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ android {
versionCode versions.publishVersionCode
versionName versions.publishVersion
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

kapt {
@@ -87,6 +88,9 @@ dependencies {
if (!rootProject.ext.isRunAloneModule2) {
implementation project(':module2')
}
if (!rootProject.ext.isRunAloneIflytek) {
implementation project(':iflytek')
}
//美团walle打包
implementation "com.meituan.android.walle:library:${versions.walle}"
//Arouter路由
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
android:name=".WelcomeActivity"
android:theme="@style/BaseAppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
2 changes: 1 addition & 1 deletion base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
android:value="portrait|landscape" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.heyongrui.base.fileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
19 changes: 19 additions & 0 deletions base/src/main/java/com/heyongrui/base/app/BaseApplication.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ public void onCreate() {
//注册网络状态监听器
NetStateChangeReceiver.registerReceiver(this);
registerActivityLife();
modulesApplicationInit();
}

private void initX5Webview() {
@@ -121,4 +122,22 @@ private void initializeInjector() {
.appModule(new AppModule(this))
.build();
}

private void modulesApplicationInit() {
for (String moduleImpl : ModuleConfig.MODULESLIST) {
try {
Class<?> clazz = Class.forName(moduleImpl);
Object obj = clazz.newInstance();
if (obj instanceof BaseApplicationImpl) {
((BaseApplicationImpl) obj).onCreate(this);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.heyongrui.base.app;

public interface BaseApplicationImpl {
void onCreate(BaseApplication application);
}
7 changes: 7 additions & 0 deletions base/src/main/java/com/heyongrui/base/app/ModuleConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.heyongrui.base.app;

public class ModuleConfig {
public static final String[] MODULESLIST = {
"com.heyongrui.iflytek.mscv5plusdemo.IflytedApplicationImpl"
};
}
Original file line number Diff line number Diff line change
@@ -49,4 +49,6 @@ public class ConfigConstants {
public static final String PATH_WELFARE = "/module2/welfare";
public static final String PATH_ABOUT = "/module2/about";
public static final String PATH_ENCOURAGE = "/module2/encourage";
//科大讯飞Iflytek模块路径
public static final String PATH_VOICE_DICATION_PROVIDER = "/iflytek/service";
}
Original file line number Diff line number Diff line change
@@ -46,10 +46,8 @@ public void onSuccess(Postcard postcard) {
if (null != postcard) {
String targetPath = postcard.getPath();
bundle = postcard.getExtras();
if (!TextUtils.isEmpty(targetPath)) {
if (!TextUtils.equals(ConfigConstants.PATH_LOGIN, targetPath)) {
bundle.putString(ConfigConstants.PATH_TARGET, targetPath);
}
if (null != bundle && !TextUtils.isEmpty(targetPath) && !TextUtils.equals(ConfigConstants.PATH_LOGIN, targetPath)) {
bundle.putString(ConfigConstants.PATH_TARGET, targetPath);
}
}
ARouter.getInstance().build(ConfigConstants.PATH_LOGIN)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.heyongrui.base.provider;

import android.content.Context;

import com.alibaba.android.arouter.facade.template.IProvider;

public interface IIflytekProvider extends IProvider {

void initialize(Context context);

void startDictation(VoiceDictationListener voiceDictationListener);

void stopDictation();

void cancelDictation();

void uploadContact();

void uploadUserWords();

void release();

interface VoiceDictationListener {
void onResult(String result, boolean isSuccess);
}
}
3 changes: 2 additions & 1 deletion base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name">base</string>
<string name="exit_tip">再按一次退出程序</string>
<string name="app_intro">“优聚”是一款集多种优秀资源和实用功能的APP,打破传统限制,融合多元,发现更多、更优秀、更有趣的东西。后续也会加入更多新的功能。也欢迎各位提出意见。</string>
<string name="app_intro">“优聚”是一款集多个平台的资讯内容、复合型优秀资源和实用功能的APP,打破传统限制,融合多元,发现更多、更优秀、更有趣的东西。后续也会加入更多新的功能。也欢迎各位提出意见。</string>
<string name="update_url">https://raw.githubusercontent.com/HeYongRui/YouJu/master/app/version_update.json</string>
<string name="update_title">更新提示</string>
<string name="update_error">更新失败</string>
@@ -15,6 +15,7 @@
<string name="cancel">取消</string>
<string name="permisson_title">权限提示</string>
<string name="read_write_permisson">此功能需要开启读写权限</string>
<string name="related_permisson">此功能需要开启相关权限</string>
<string name="install_permisson">请开启安装权限</string>
<string name="system_title">系统提示</string>
<string name="go_setting">设定</string>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ allprojects {
mavenCentral()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
maven { url 'http://libmsc.xfyun.cn/repository/maven-releases/' }
}
}

1 change: 1 addition & 0 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ ext {
isRunAloneUser = false;//user模块是否可以单独运行
isRunAloneModule = false;//module模块是否可以单独运行
isRunAloneModule2 = false;//module2模块是否可以单独运行
isRunAloneIflytek = false;//科大讯飞模块是否可以单独运行
//版本号控制
versions = [
//Project
65 changes: 65 additions & 0 deletions iflytek/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
103 changes: 103 additions & 0 deletions iflytek/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
if (rootProject.ext.isRunAloneIflytek) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion versions.compileSdk

defaultConfig {
if (rootProject.ext.isRunAloneIflytek) {
applicationId "com.heyongrui.iflytek"
multiDexEnabled true
}
minSdkVersion versions.minSdk
targetSdkVersion versions.compileSdk
versionCode versions.publishVersionCode
versionName versions.publishVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
// javaCompileOptions {
// annotationProcessorOptions {
// arguments = [AROUTER_MODULE_NAME: project.getName()]
// }
// }
}

signingConfigs {
release {
storeFile file("../keystore.jks")
storePassword "111111"
keyAlias "youju"
keyPassword "111111"
}

debug {
storeFile file("../keystore.jks")
storePassword "111111"
keyAlias "youju"
keyPassword "111111"
}
}

buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}

compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}

sourceSets {
main {
if (rootProject.ext.isRunAloneIflytek) {
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
java.srcDirs = ['src/main/debug/java/', 'src/main/java/']
res.srcDirs = ['src/main/debug/res', 'src/main/res']
} else {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java/']
res.srcDirs = ['src/main/res']
java {
exclude 'src/main/debug/**'
}
}

}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':base')
implementation project(':network')
//Arouter路由
kapt "com.alibaba:arouter-compiler:${versions.arouterCompiler}"
//dagger
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Binary file added iflytek/libs/Msc.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions iflytek/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.heyongrui.iflytek;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.heyongrui.iflytek.test", appContext.getPackageName());
}
}
62 changes: 62 additions & 0 deletions iflytek/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.heyongrui.iflytek">

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

<application>
<activity
android:name=".mscv5plusdemo.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".speech.setting.TtsSettings"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".speech.setting.IatSettings"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.IatDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.AsrDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.TtsDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.IvwActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.WakeDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" />
<activity
android:name=".mscv5plusdemo.OneShotDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
</application>

</manifest>
12 changes: 12 additions & 0 deletions iflytek/src/main/assets/call.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#BNF+IAT 1.0 UTF-8;
!grammar call;
!slot <contact>;
!slot <callPre>;
!slot <callPhone>;
!slot <callTo>;
!start <callStart>;
<callStart>:[<callPre>][<callTo>]<contact><callPhone>|[<callPre>]<callPhone>[<callTo>]<contact>;
<contact>:张海洋;
<callPre>:我要|我想|我想要;
<callPhone>:打电话;
<callTo>:给;
8 changes: 8 additions & 0 deletions iflytek/src/main/assets/grammar_sample.abnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ABNF 1.0 UTF-8;
language zh-CN;
mode voice;

root $main;
$main = $place1 到 $place2;
$place1 = 北京|武汉|南京|天津|东京;
$place2 = 上海|合肥;
Binary file added iflytek/src/main/assets/iat/common.jet
Binary file not shown.
Binary file added iflytek/src/main/assets/iat/sms_16k.jet
Binary file not shown.
Binary file added iflytek/src/main/assets/iattest.wav
Binary file not shown.
Binary file added iflytek/src/main/assets/iflytek/recognize.xml
Binary file not shown.
Binary file added iflytek/src/main/assets/iflytek/voice_bg.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/assets/iflytek/voice_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/assets/iflytek/voice_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/assets/iflytek/waiting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/assets/iflytek/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions iflytek/src/main/assets/userwords
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"userword":[{"name":"我的常用词","words":["佳晨实业","蜀南庭苑","高兰路","复联二"]},{"name":"我的好友","words":["李馨琪","鹿晓雷","张集栋","周家莉","叶震珂","熊泽萌"]}]}
8 changes: 8 additions & 0 deletions iflytek/src/main/assets/wake.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#BNF+IAT 1.0 UTF-8;
!grammar wake;
!slot <callCmd>;
!slot <contact>;
!start <callStart>;
<callStart>:[<callCmd>]<callName>;
<callCmd>:讯飞语音|讯飞语点|叮咚叮咚;
<callName>:张三|李四|张海洋;
8 changes: 8 additions & 0 deletions iflytek/src/main/assets/wake_grammar_sample.abnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ABNF 1.0 UTF-8;
language zh-CN;
mode voice;

root $main;
$main = [$call] $name;
$call = 讯飞语音|讯飞语点|叮咚叮咚;
$name = 张三|李四|张海洋;
76 changes: 76 additions & 0 deletions iflytek/src/main/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.heyongrui.iflytek">

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

<application
android:name=".IflytedApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/BaseAppTheme"
tools:replace="android:name">
<activity
android:name=".mscv5plusdemo.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".speech.setting.TtsSettings"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".speech.setting.IatSettings"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.IatDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.AsrDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.TtsDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.IvwActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
<activity
android:name=".mscv5plusdemo.WakeDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" />
<activity
android:name=".mscv5plusdemo.OneShotDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait"
android:theme="@style/BaseAppTheme" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.heyongrui.iflytek;

import com.heyongrui.base.app.BaseApplication;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;

public class IflytedApplication extends BaseApplication {

@Override
public void onCreate() {
super.onCreate();
// 应用程序入口处调用,避免手机内存过小,杀死后台进程后通过历史intent进入Activity造成SpeechUtility对象为null
// 注意:此接口在非主进程调用会返回null对象,如需在非主进程使用语音功能,请增加参数:SpeechConstant.FORCE_LOGIN+"=true"
// 参数间使用“,”分隔。
// 设置你申请的应用appid
// 注意: appid 必须和下载的SDK保持一致,否则会出现10407错误
StringBuffer param = new StringBuffer();
param.append("appid=" + getString(R.string.app_id));
param.append(",");
// 设置使用v5+
param.append(SpeechConstant.ENGINE_MODE + "=" + SpeechConstant.MODE_MSC);
SpeechUtility.createUtility(this, param.toString());
}
}
401 changes: 401 additions & 0 deletions iflytek/src/main/java/com/heyongrui/iflytek/mscv5plusdemo/AsrDemo.java

Large diffs are not rendered by default.

439 changes: 439 additions & 0 deletions iflytek/src/main/java/com/heyongrui/iflytek/mscv5plusdemo/IatDemo.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import com.heyongrui.base.app.BaseApplication;
import com.heyongrui.base.app.BaseApplicationImpl;
import com.heyongrui.iflytek.R;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;

public class IflytedApplicationImpl implements BaseApplicationImpl {

@Override
public void onCreate(BaseApplication application) {
// 应用程序入口处调用,避免手机内存过小,杀死后台进程后通过历史intent进入Activity造成SpeechUtility对象为null
// 注意:此接口在非主进程调用会返回null对象,如需在非主进程使用语音功能,请增加参数:SpeechConstant.FORCE_LOGIN+"=true"
// 参数间使用“,”分隔。
// 设置你申请的应用appid
// 注意: appid 必须和下载的SDK保持一致,否则会出现10407错误
StringBuffer param = new StringBuffer();
param.append("appid=" + application.getString(R.string.app_id));
param.append(",");
// 设置使用v5+
param.append(SpeechConstant.ENGINE_MODE + "=" + SpeechConstant.MODE_MSC);
SpeechUtility.createUtility(application, param.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

import com.heyongrui.iflytek.R;
import com.iflytek.cloud.VoiceWakeuper;


public class IvwActivity extends Activity implements OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.ivw_activity);

((Button) findViewById(R.id.btn_wake)).setOnClickListener(IvwActivity.this);
((Button) findViewById(R.id.btn_oneshot)).setOnClickListener(IvwActivity.this);

}

@Override
public void onClick(View v) {
if (null == VoiceWakeuper.createWakeuper(this, null)) {
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
Toast.makeText(this
, "创建对象失败,请确认 libmsc.so 放置正确,\n 且有调用 createUtility 进行初始化"
, Toast.LENGTH_LONG).show();
return;
}

Intent intent = null;
int i = v.getId();
if (i == R.id.btn_wake) {
intent = new Intent(IvwActivity.this, WakeDemo.class);
startActivity(intent);
} else if (i == R.id.btn_oneshot) {
intent = new Intent(IvwActivity.this, OneShotDemo.class);
startActivity(intent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;

import com.heyongrui.iflytek.R;


public class MainActivity extends Activity implements OnClickListener {

private Toast mToast;

@SuppressLint("ShowToast")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置标题栏(无标题)
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
requestPermissions();
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
SimpleAdapter listitemAdapter = new SimpleAdapter();
((ListView) findViewById(R.id.listview_main)).setAdapter(listitemAdapter);
}

@Override
public void onClick(View view) {
int tag = Integer.parseInt(view.getTag().toString());
Intent intent = null;
switch (tag) {
case 0:
// 语音听写
intent = new Intent(this, IatDemo.class);
break;
case 1:
// 语法识别
intent = new Intent(this, AsrDemo.class);
break;
case 2:
// 语义理解
showTip("请登录:http://www.xfyun.cn/ 下载aiui体验吧!");
break;
case 3:
// 合成
intent = new Intent(this, TtsDemo.class);
break;
case 4:
// 唤醒
intent = new Intent(this, IvwActivity.class);
break;
case 5:
// 声纹
showTip("请登录:http://www.xfyun.cn/ 下载体验吧!");
break;
default:
showTip("此功能将于近期开放,敬请期待。");
break;
}
if (intent != null) {
startActivity(intent);
}
}


//Menu 列表
String items[] = {"立刻体验语音听写", "立刻体验语法识别", "立刻体验语义理解", "立刻体验语音合成", "立刻体验语音唤醒", "立刻体验声纹密码"};

private class SimpleAdapter extends BaseAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
LayoutInflater factory = LayoutInflater.from(MainActivity.this);
View mView = factory.inflate(R.layout.list_items, null);
convertView = mView;
}
Button btn = (Button) convertView.findViewById(R.id.btn);
btn.setOnClickListener(MainActivity.this);
btn.setTag(position);
btn.setText(items[position]);
return convertView;
}

@Override
public int getCount() {
return items.length;
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}
}

private void showTip(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mToast.setText(str);
mToast.show();
}
});
}


private void requestPermissions() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission = ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.LOCATION_HARDWARE, Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_SETTINGS, Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_CONTACTS}, 0x0010);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.heyongrui.iflytek.R;
import com.heyongrui.iflytek.speech.util.JsonParser;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.GrammarListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechEvent;
import com.iflytek.cloud.SpeechRecognizer;
import com.iflytek.cloud.VoiceWakeuper;
import com.iflytek.cloud.WakeuperListener;
import com.iflytek.cloud.WakeuperResult;
import com.iflytek.cloud.util.ResourceUtil;
import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.InputStream;


public class OneShotDemo extends Activity implements OnClickListener {
private String TAG = "ivw";
private Toast mToast;
private TextView textView;
// 语音唤醒对象
private VoiceWakeuper mIvw;
// 语音识别对象
private SpeechRecognizer mAsr;
// 唤醒结果内容
private String resultString;
// 识别结果内容
private String recoString;
// 设置门限值 : 门限值越低越容易被唤醒
private TextView tvThresh;
private SeekBar seekbarThresh;
private final static int MAX = 3000;
private final static int MIN = 0;
private int curThresh = 1450;
private String threshStr = "门限值:";
// 云端语法文件
private String mCloudGrammar = null;
// 云端语法id
private String mCloudGrammarID;
// 本地语法id
private String mLocalGrammarID;
// 本地语法文件
private String mLocalGrammar = null;
// 本地语法构建路径
private String grmPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/msc/test";
// 引擎类型
private String mEngineType = SpeechConstant.TYPE_CLOUD;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.oneshot_activity);

initUI();

// 初始化唤醒对象
mIvw = VoiceWakeuper.createWakeuper(this, null);
// 初始化识别对象---唤醒+识别,用来构建语法
mAsr = SpeechRecognizer.createRecognizer(this, null);
// 初始化语法文件
mCloudGrammar = readFile(this, "wake_grammar_sample.abnf", "utf-8");
mLocalGrammar = readFile(this, "wake.bnf", "utf-8");
}

private void initUI() {
findViewById(R.id.btn_oneshot).setOnClickListener(OneShotDemo.this);
findViewById(R.id.btn_stop).setOnClickListener(OneShotDemo.this);
findViewById(R.id.btn_grammar).setOnClickListener(OneShotDemo.this);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
textView = (TextView) findViewById(R.id.txt_show_msg);
tvThresh = (TextView) findViewById(R.id.txt_thresh);

seekbarThresh = (SeekBar) findViewById(R.id.seekBar_thresh);
seekbarThresh.setMax(MAX - MIN);
seekbarThresh.setProgress(curThresh);
tvThresh.setText(threshStr + curThresh);

seekbarThresh.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar arg0) {
}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
}

@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
curThresh = seekbarThresh.getProgress() + MIN;
tvThresh.setText(threshStr + curThresh);
}
});
//选择云端or本地
RadioGroup group = (RadioGroup) this.findViewById(R.id.radioGroup);
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radioCloud) {
mEngineType = SpeechConstant.TYPE_CLOUD;
} else if (checkedId == R.id.radioLocal) {
mEngineType = SpeechConstant.TYPE_LOCAL;
}
}
});
}

GrammarListener grammarListener = new GrammarListener() {
@Override
public void onBuildFinish(String grammarId, SpeechError error) {
if (error == null) {
if (mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
mCloudGrammarID = grammarId;
} else {
mLocalGrammarID = grammarId;
}
showTip("语法构建成功:" + grammarId);
} else {
showTip("语法构建失败,错误码:" + error.getErrorCode() + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
};

@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_oneshot) {// 非空判断,防止因空指针使程序崩溃
mIvw = VoiceWakeuper.getWakeuper();
if (mIvw != null) {
resultString = "";
recoString = "";
textView.setText(resultString);

final String resPath = ResourceUtil.generateResourcePath(this, RESOURCE_TYPE.assets, "ivw/" + getString(R.string.app_id) + ".jet");
// 清空参数
mIvw.setParameter(SpeechConstant.PARAMS, null);
// 设置识别引擎
mIvw.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
// 设置唤醒资源路径
mIvw.setParameter(ResourceUtil.IVW_RES_PATH, resPath);
/**
* 唤醒门限值,根据资源携带的唤醒词个数按照“id:门限;id:门限”的格式传入
* 示例demo默认设置第一个唤醒词,建议开发者根据定制资源中唤醒词个数进行设置
*/
mIvw.setParameter(SpeechConstant.IVW_THRESHOLD, "0:"
+ curThresh);
// 设置唤醒+识别模式
mIvw.setParameter(SpeechConstant.IVW_SST, "oneshot");
// 设置返回结果格式
mIvw.setParameter(SpeechConstant.RESULT_TYPE, "json");
//
// mIvw.setParameter(SpeechConstant.IVW_SHOT_WORD, "0");

// 设置唤醒录音保存路径,保存最近一分钟的音频
mIvw.setParameter(SpeechConstant.IVW_AUDIO_PATH, Environment.getExternalStorageDirectory().getPath() + "/msc/ivw.wav");
mIvw.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");

if (mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
if (!TextUtils.isEmpty(mCloudGrammarID)) {
// 设置云端识别使用的语法id
mIvw.setParameter(SpeechConstant.CLOUD_GRAMMAR,
mCloudGrammarID);
mIvw.startListening(mWakeuperListener);
} else {
showTip("请先构建语法");
}
} else {
if (!TextUtils.isEmpty(mLocalGrammarID)) {
// 设置本地识别资源
mIvw.setParameter(ResourceUtil.ASR_RES_PATH,
getResourcePath());
// 设置语法构建路径
mIvw.setParameter(ResourceUtil.GRM_BUILD_PATH, grmPath);
// 设置本地识别使用语法id
mIvw.setParameter(SpeechConstant.LOCAL_GRAMMAR,
mLocalGrammarID);
mIvw.startListening(mWakeuperListener);
} else {
showTip("请先构建语法");
}
}

} else {
showTip("唤醒未初始化");
}
} else if (i == R.id.btn_grammar) {
int ret = 0;
if (mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
// 设置参数
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
mAsr.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
// 开始构建语法
ret = mAsr.buildGrammar("abnf", mCloudGrammar, grammarListener);
if (ret != ErrorCode.SUCCESS) {
showTip("语法构建失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
} else {
mAsr.setParameter(SpeechConstant.PARAMS, null);
mAsr.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
// 设置引擎类型
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
// 设置语法构建路径
mAsr.setParameter(ResourceUtil.GRM_BUILD_PATH, grmPath);
// 设置资源路径
mAsr.setParameter(ResourceUtil.ASR_RES_PATH, getResourcePath());
ret = mAsr.buildGrammar("bnf", mLocalGrammar, grammarListener);
if (ret != ErrorCode.SUCCESS) {
showTip("语法构建失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
} else if (i == R.id.btn_stop) {
mIvw = VoiceWakeuper.getWakeuper();
if (mIvw != null) {
mIvw.stopListening();
} else {
showTip("唤醒未初始化");
}
}
}

private WakeuperListener mWakeuperListener = new WakeuperListener() {

@Override
public void onResult(WakeuperResult result) {
try {
String text = result.getResultString();
JSONObject object;
object = new JSONObject(text);
StringBuffer buffer = new StringBuffer();
buffer.append("【RAW】 " + text);
buffer.append("\n");
buffer.append("【操作类型】" + object.optString("sst"));
buffer.append("\n");
buffer.append("【唤醒词id】" + object.optString("id"));
buffer.append("\n");
buffer.append("【得分】" + object.optString("score"));
buffer.append("\n");
buffer.append("【前端点】" + object.optString("bos"));
buffer.append("\n");
buffer.append("【尾端点】" + object.optString("eos"));
resultString = buffer.toString();
} catch (JSONException e) {
resultString = "结果解析出错";
e.printStackTrace();
}
textView.setText(resultString);
}

@Override
public void onError(SpeechError error) {
showTip(error.getPlainDescription(true));
}

@Override
public void onBeginOfSpeech() {
showTip("开始说话");
}

@Override
public void onEvent(int eventType, int isLast, int arg2, Bundle obj) {
Log.d(TAG, "eventType:" + eventType + "arg1:" + isLast + "arg2:" + arg2);
// 识别结果
if (SpeechEvent.EVENT_IVW_RESULT == eventType) {
RecognizerResult reslut = ((RecognizerResult) obj.get(SpeechEvent.KEY_EVENT_IVW_RESULT));
recoString += JsonParser.parseGrammarResult(reslut.getResultString());
textView.setText(recoString);
}
}

@Override
public void onVolumeChanged(int volume) {
}

};

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy OneShotDemo");
mIvw = VoiceWakeuper.getWakeuper();
if (mIvw != null) {
mIvw.destroy();
} else {
showTip("唤醒未初始化");
}
}

/**
* 读取asset目录下文件。
*
* @return content
*/
public static String readFile(Context mContext, String file, String code) {
int len = 0;
byte[] buf = null;
String result = "";
try {
InputStream in = mContext.getAssets().open(file);
len = in.available();
buf = new byte[len];
in.read(buf, 0, len);

result = new String(buf, code);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

// 获取识别资源路径
private String getResourcePath() {
StringBuffer tempBuffer = new StringBuffer();
// 识别通用资源
tempBuffer.append(ResourceUtil.generateResourcePath(this,
RESOURCE_TYPE.assets, "asr/common.jet"));
return tempBuffer.toString();
}

private void showTip(final String str) {
mToast.setText(str);
mToast.show();
}

}
354 changes: 354 additions & 0 deletions iflytek/src/main/java/com/heyongrui/iflytek/mscv5plusdemo/TtsDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

import com.heyongrui.iflytek.R;
import com.heyongrui.iflytek.speech.setting.TtsSettings;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;
import com.iflytek.cloud.util.ResourceUtil;
import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;

public class TtsDemo extends Activity implements OnClickListener {
private static String TAG = TtsDemo.class.getSimpleName();
// 语音合成对象
private SpeechSynthesizer mTts;

// 默认云端发音人
public static String voicerCloud = "xiaoyan";
// 默认本地发音人
public static String voicerLocal = "xiaoyan";


// 云端发音人列表
private String[] cloudVoicersEntries;
private String[] cloudVoicersValue;

// 本地发音人列表
private String[] localVoicersEntries;
private String[] localVoicersValue;

//缓冲进度
private int mPercentForBuffering = 0;
//播放进度
private int mPercentForPlaying = 0;

// 云端/本地选择按钮
private RadioGroup mRadioGroup;
// 引擎类型
private String mEngineType = SpeechConstant.TYPE_CLOUD;

private Toast mToast;
private SharedPreferences mSharedPreferences;

@SuppressLint("ShowToast")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.ttsdemo);
initLayout();

// 初始化合成对象
mTts = SpeechSynthesizer.createSynthesizer(this, mTtsInitListener);

// 云端发音人名称列表
cloudVoicersEntries = getResources().getStringArray(R.array.voicer_cloud_entries);
cloudVoicersValue = getResources().getStringArray(R.array.voicer_cloud_values);

// 本地发音人名称列表
localVoicersEntries = getResources().getStringArray(R.array.voicer_local_entries);
localVoicersValue = getResources().getStringArray(R.array.voicer_local_values);

mSharedPreferences = getSharedPreferences(TtsSettings.PREFER_NAME, Activity.MODE_PRIVATE);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
}

/**
* 初始化Layout。
*/
private void initLayout() {
findViewById(R.id.tts_play).setOnClickListener(this);

findViewById(R.id.tts_cancel).setOnClickListener(this);
findViewById(R.id.tts_pause).setOnClickListener(this);
findViewById(R.id.tts_resume).setOnClickListener(this);
findViewById(R.id.image_tts_set).setOnClickListener(this);

findViewById(R.id.tts_btn_person_select).setOnClickListener(this);

mRadioGroup = ((RadioGroup) findViewById(R.id.tts_rediogroup));
mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.tts_radioCloud) {
mEngineType = SpeechConstant.TYPE_CLOUD;
} else if (checkedId == R.id.tts_radioLocal) {
mEngineType = SpeechConstant.TYPE_LOCAL;
}
}
});
}

@Override
public void onClick(View view) {
if (null == mTts) {
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
this.showTip("创建对象失败,请确认 libmsc.so 放置正确,\n 且有调用 createUtility 进行初始化");
return;
}

int i = view.getId();
if (i == R.id.image_tts_set) {
Intent intent = new Intent(TtsDemo.this, TtsSettings.class);
startActivity(intent);
// 开始合成
// 收到onCompleted 回调时,合成结束、生成合成音频
// 合成的音频格式:只支持pcm格式
} else if (i == R.id.tts_play) {
String text = ((EditText) findViewById(R.id.tts_text)).getText().toString();
// 设置参数
setParam();
int code = mTts.startSpeaking(text, mTtsListener);
// /**
// * 只保存音频不进行播放接口,调用此接口请注释startSpeaking接口
// * text:要合成的文本,uri:需要保存的音频全路径,listener:回调接口
// */
// String path = Environment.getExternalStorageDirectory()+"/tts.pcm";
// int code = mTts.synthesizeToUri(text, path, mTtsListener);

if (code != ErrorCode.SUCCESS) {
showTip("语音合成失败,错误码: " + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
// 取消合成
} else if (i == R.id.tts_cancel) {
mTts.stopSpeaking();
// 暂停播放
} else if (i == R.id.tts_pause) {
mTts.pauseSpeaking();
// 继续播放
} else if (i == R.id.tts_resume) {
mTts.resumeSpeaking();
// 选择发音人
} else if (i == R.id.tts_btn_person_select) {
showPresonSelectDialog();
}
}


private static int selectedNumCloud = 0;
private static int selectedNumLocal = 0;

/**
* 发音人选择。
*/
private void showPresonSelectDialog() {
int i = mRadioGroup.getCheckedRadioButtonId();// 选择在线合成
if (i == R.id.tts_radioCloud) {
new AlertDialog.Builder(this).setTitle("在线合成发音人选项")
.setSingleChoiceItems(cloudVoicersEntries, // 单选框有几项,各是什么名字
selectedNumCloud, // 默认的选项
new DialogInterface.OnClickListener() { // 点击单选框后的处理
public void onClick(DialogInterface dialog,
int which) { // 点击了哪一项
voicerCloud = cloudVoicersValue[which];
if ("catherine".equals(voicerCloud) || "henry".equals(voicerCloud) || "vimary".equals(voicerCloud)) {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source_en);
} else {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source);
}
selectedNumCloud = which;
dialog.dismiss();
}
}).show();

// 选择本地合成
} else if (i == R.id.tts_radioLocal) {
new AlertDialog.Builder(this).setTitle("本地合成发音人选项")
.setSingleChoiceItems(localVoicersEntries, // 单选框有几项,各是什么名字
selectedNumLocal, // 默认的选项
new DialogInterface.OnClickListener() { // 点击单选框后的处理
public void onClick(DialogInterface dialog,
int which) { // 点击了哪一项
voicerLocal = localVoicersValue[which];
if ("catherine".equals(voicerLocal) || "henry".equals(voicerLocal) || "vimary".equals(voicerLocal)) {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source_en);
} else {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source);
}
selectedNumLocal = which;
dialog.dismiss();
}
}).show();
}
}

/**
* 初始化监听。
*/
private InitListener mTtsInitListener = new InitListener() {
@Override
public void onInit(int code) {
Log.d(TAG, "InitListener init() code = " + code);
if (code != ErrorCode.SUCCESS) {
showTip("初始化失败,错误码:" + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
} else {
// 初始化成功,之后可以调用startSpeaking方法
// 注:有的开发者在onCreate方法中创建完合成对象之后马上就调用startSpeaking进行合成,
// 正确的做法是将onCreate中的startSpeaking调用移至这里
}
}
};

/**
* 合成回调监听。
*/
private SynthesizerListener mTtsListener = new SynthesizerListener() {

@Override
public void onSpeakBegin() {
showTip("开始播放");
}

@Override
public void onSpeakPaused() {
showTip("暂停播放");
}

@Override
public void onSpeakResumed() {
showTip("继续播放");
}

@Override
public void onBufferProgress(int percent, int beginPos, int endPos,
String info) {
// 合成进度
mPercentForBuffering = percent;
showTip(String.format(getString(R.string.tts_toast_format),
mPercentForBuffering, mPercentForPlaying));
}

@Override
public void onSpeakProgress(int percent, int beginPos, int endPos) {
// 播放进度
mPercentForPlaying = percent;
showTip(String.format(getString(R.string.tts_toast_format),
mPercentForBuffering, mPercentForPlaying));
}

@Override
public void onCompleted(SpeechError error) {
if (error == null) {
showTip("播放完成");
} else if (error != null) {
showTip(error.getPlainDescription(true));
}
}

@Override
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
// 若使用本地能力,会话id为null
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
// Log.d(TAG, "session id =" + sid);
// }

//实时音频流输出参考
/*if (SpeechEvent.EVENT_TTS_BUFFER == eventType) {
byte[] buf = obj.getByteArray(SpeechEvent.KEY_EVENT_TTS_BUFFER);
Log.e("MscSpeechLog", "buf is =" + buf);
}*/
}
};

private void showTip(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mToast.setText(str);
mToast.show();
}
});
}

/**
* 参数设置
*/
private void setParam() {
// 清空参数
mTts.setParameter(SpeechConstant.PARAMS, null);
//设置合成
if (mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
//设置使用云端引擎
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
//设置发音人
mTts.setParameter(SpeechConstant.VOICE_NAME, voicerCloud);
} else {
//设置使用本地引擎
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
//设置发音人资源路径
mTts.setParameter(ResourceUtil.TTS_RES_PATH, getResourcePath());
//设置发音人
mTts.setParameter(SpeechConstant.VOICE_NAME, voicerLocal);
}
//mTts.setParameter(SpeechConstant.TTS_DATA_NOTIFY,"1");//支持实时音频流抛出,仅在synthesizeToUri条件下支持
//设置合成语速
mTts.setParameter(SpeechConstant.SPEED, mSharedPreferences.getString("speed_preference", "50"));
//设置合成音调
mTts.setParameter(SpeechConstant.PITCH, mSharedPreferences.getString("pitch_preference", "50"));
//设置合成音量
mTts.setParameter(SpeechConstant.VOLUME, mSharedPreferences.getString("volume_preference", "50"));
//设置播放器音频流类型
mTts.setParameter(SpeechConstant.STREAM_TYPE, mSharedPreferences.getString("stream_preference", "3"));

// 设置播放合成音频打断音乐播放,默认为true
mTts.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "true");

// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/msc/tts.wav");
}

//获取发音人资源路径
private String getResourcePath() {
StringBuffer tempBuffer = new StringBuffer();
//合成通用资源
tempBuffer.append(ResourceUtil.generateResourcePath(this, RESOURCE_TYPE.assets, "tts/common.jet"));
tempBuffer.append(";");
//发音人资源
tempBuffer.append(ResourceUtil.generateResourcePath(this, RESOURCE_TYPE.assets, "tts/" + TtsDemo.voicerLocal + ".jet"));
return tempBuffer.toString();
}

@Override
protected void onDestroy() {
super.onDestroy();

if (null != mTts) {
mTts.stopSpeaking();
// 退出时释放连接
mTts.destroy();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
package com.heyongrui.iflytek.mscv5plusdemo;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.heyongrui.iflytek.R;
import com.iflytek.cloud.RequestListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechEvent;
import com.iflytek.cloud.VoiceWakeuper;
import com.iflytek.cloud.WakeuperListener;
import com.iflytek.cloud.WakeuperResult;
import com.iflytek.cloud.util.ResourceUtil;
import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;


public class WakeDemo extends Activity implements OnClickListener {
private String TAG = "ivw";
private Toast mToast;
private TextView textView;
// 语音唤醒对象
private VoiceWakeuper mIvw;
// 唤醒结果内容
private String resultString;

// 设置门限值 : 门限值越低越容易被唤醒
private TextView tvThresh;
private SeekBar seekbarThresh;
private final static int MAX = 3000;
private final static int MIN = 0;
private int curThresh = 1450;
private String threshStr = "门限值:";
private String keep_alive = "1";
private String ivwNetMode = "0";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.wake_activity);

initUi();
// 初始化唤醒对象
mIvw = VoiceWakeuper.createWakeuper(this, null);
}

@SuppressLint("ShowToast")
private void initUi() {
findViewById(R.id.btn_start).setOnClickListener(this);
findViewById(R.id.btn_stop).setOnClickListener(this);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
textView = (TextView) findViewById(R.id.txt_show_msg);
tvThresh = (TextView) findViewById(R.id.txt_thresh);
seekbarThresh = (SeekBar) findViewById(R.id.seekBar_thresh);
seekbarThresh.setMax(MAX - MIN);
seekbarThresh.setProgress(curThresh);
tvThresh.setText(threshStr + curThresh);
seekbarThresh.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar arg0) {
}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
}

@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
curThresh = seekbarThresh.getProgress() + MIN;
tvThresh.setText(threshStr + curThresh);
}
});

RadioGroup group = (RadioGroup) findViewById(R.id.ivw_net_mode);
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
/**
* 闭环优化网络模式有三种:
* 模式0:关闭闭环优化功能
*
* 模式1:开启闭环优化功能,允许上传优化数据。需开发者自行管理优化资源。
* sdk提供相应的查询和下载接口,请开发者参考API文档,具体使用请参考本示例
* queryResource及downloadResource方法;
*
* 模式2:开启闭环优化功能,允许上传优化数据及启动唤醒时进行资源查询下载;
* 本示例为方便开发者使用仅展示模式0和模式2;
*/
if (arg1 == R.id.mode_close) {
ivwNetMode = "0";
} else if (arg1 == R.id.mode_open) {
ivwNetMode = "1";
}
}
});
}

@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_start) {//非空判断,防止因空指针使程序崩溃
mIvw = VoiceWakeuper.getWakeuper();
if (mIvw != null) {
setRadioEnable(false);
resultString = "";
textView.setText(resultString);

// 清空参数
mIvw.setParameter(SpeechConstant.PARAMS, null);
// 唤醒门限值,根据资源携带的唤醒词个数按照“id:门限;id:门限”的格式传入
mIvw.setParameter(SpeechConstant.IVW_THRESHOLD, "0:" + curThresh);
// 设置唤醒模式
mIvw.setParameter(SpeechConstant.IVW_SST, "wakeup");
// 设置持续进行唤醒
mIvw.setParameter(SpeechConstant.KEEP_ALIVE, keep_alive);
// 设置闭环优化网络模式
mIvw.setParameter(SpeechConstant.IVW_NET_MODE, ivwNetMode);
// 设置唤醒资源路径
mIvw.setParameter(SpeechConstant.IVW_RES_PATH, getResource());
// 设置唤醒录音保存路径,保存最近一分钟的音频
mIvw.setParameter(SpeechConstant.IVW_AUDIO_PATH, Environment.getExternalStorageDirectory().getPath() + "/msc/ivw.wav");
mIvw.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
// 如有需要,设置 NOTIFY_RECORD_DATA 以实时通过 onEvent 返回录音音频流字节
//mIvw.setParameter( SpeechConstant.NOTIFY_RECORD_DATA, "1" );

// 启动唤醒
mIvw.startListening(mWakeuperListener);
} else {
showTip("唤醒未初始化");
}
} else if (i == R.id.btn_stop) {
mIvw.stopListening();
setRadioEnable(true);
}
}

/**
* 查询闭环优化唤醒资源
* 请在闭环优化网络模式1或者模式2使用
*/
public void queryResource() {
int ret = mIvw.queryResource(getResource(), requestListener);
showTip("updateResource ret:" + ret);
}


// 查询资源请求回调监听
private RequestListener requestListener = new RequestListener() {
@Override
public void onEvent(int eventType, Bundle params) {
// 以下代码用于获取查询会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
//if(SpeechEvent.EVENT_SESSION_ID == eventType) {
// Log.d(TAG, "sid:"+params.getString(SpeechEvent.KEY_EVENT_SESSION_ID));
//}
}

@Override
public void onCompleted(SpeechError error) {
if (error != null) {
Log.d(TAG, "error:" + error.getErrorCode());
showTip(error.getPlainDescription(true));
}
}

@Override
public void onBufferReceived(byte[] buffer) {
try {
String resultInfo = new String(buffer, "utf-8");
Log.d(TAG, "resultInfo:" + resultInfo);

JSONTokener tokener = new JSONTokener(resultInfo);
JSONObject object = new JSONObject(tokener);

int ret = object.getInt("ret");
if (ret == 0) {
String uri = object.getString("dlurl");
String md5 = object.getString("md5");
Log.d(TAG, "uri:" + uri);
Log.d(TAG, "md5:" + md5);
showTip("请求成功");
}
} catch (Exception e) {
e.printStackTrace();
}
}
};


private WakeuperListener mWakeuperListener = new WakeuperListener() {

@Override
public void onResult(WakeuperResult result) {
Log.d(TAG, "onResult");
if (!"1".equalsIgnoreCase(keep_alive)) {
setRadioEnable(true);
}
try {
String text = result.getResultString();
JSONObject object;
object = new JSONObject(text);
StringBuffer buffer = new StringBuffer();
buffer.append("【RAW】 " + text);
buffer.append("\n");
buffer.append("【操作类型】" + object.optString("sst"));
buffer.append("\n");
buffer.append("【唤醒词id】" + object.optString("id"));
buffer.append("\n");
buffer.append("【得分】" + object.optString("score"));
buffer.append("\n");
buffer.append("【前端点】" + object.optString("bos"));
buffer.append("\n");
buffer.append("【尾端点】" + object.optString("eos"));
resultString = buffer.toString();
} catch (JSONException e) {
resultString = "结果解析出错";
e.printStackTrace();
}
textView.setText(resultString);
}

@Override
public void onError(SpeechError error) {
showTip(error.getPlainDescription(true));
setRadioEnable(true);
}

@Override
public void onBeginOfSpeech() {
}

@Override
public void onEvent(int eventType, int isLast, int arg2, Bundle obj) {
switch (eventType) {
// EVENT_RECORD_DATA 事件仅在 NOTIFY_RECORD_DATA 参数值为 真 时返回
case SpeechEvent.EVENT_RECORD_DATA:
final byte[] audio = obj.getByteArray(SpeechEvent.KEY_EVENT_RECORD_DATA);
Log.i(TAG, "ivw audio length: " + audio.length);
break;
}
}

@Override
public void onVolumeChanged(int volume) {

}
};

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy WakeDemo");
// 销毁合成对象
mIvw = VoiceWakeuper.getWakeuper();
if (mIvw != null) {
mIvw.destroy();
}
}

private String getResource() {
final String resPath = ResourceUtil.generateResourcePath(WakeDemo.this, RESOURCE_TYPE.assets, "ivw/" + getString(R.string.app_id) + ".jet");
Log.d(TAG, "resPath: " + resPath);
return resPath;
}

private void showTip(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mToast.setText(str);
mToast.show();
}
});
}

private void setRadioEnable(final boolean enabled) {
runOnUiThread(new Runnable() {
@Override
public void run() {
findViewById(R.id.ivw_net_mode).setEnabled(enabled);
findViewById(R.id.btn_start).setEnabled(enabled);
findViewById(R.id.seekBar_thresh).setEnabled(enabled);
}
});
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.heyongrui.iflytek.speech.setting;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.view.Window;

import com.heyongrui.iflytek.R;
import com.heyongrui.iflytek.speech.util.SettingTextWatcher;


/**
* 听写设置界面
*/
public class IatSettings extends PreferenceActivity implements OnPreferenceChangeListener {

public static final String PREFER_NAME = "com.iflytek.setting";
private EditTextPreference mVadbosPreference;
private EditTextPreference mVadeosPreference;

@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.iat_setting);

mVadbosPreference = (EditTextPreference) findPreference("iat_vadbos_preference");
mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadbosPreference, 0, 10000));

mVadeosPreference = (EditTextPreference) findPreference("iat_vadeos_preference");
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadeosPreference, 0, 10000));
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.heyongrui.iflytek.speech.setting;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.view.Window;

import com.heyongrui.iflytek.R;
import com.heyongrui.iflytek.speech.util.SettingTextWatcher;


/**
* 合成设置界面
*/
public class TtsSettings extends PreferenceActivity implements OnPreferenceChangeListener {

public static final String PREFER_NAME = "com.iflytek.setting";
private EditTextPreference mSpeedPreference;
private EditTextPreference mPitchPreference;
private EditTextPreference mVolumePreference;

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
// 指定保存文件名字
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.tts_setting);
mSpeedPreference = (EditTextPreference) findPreference("speed_preference");
mSpeedPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mSpeedPreference, 0, 200));

mPitchPreference = (EditTextPreference) findPreference("pitch_preference");
mPitchPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mPitchPreference, 0, 100));

mVolumePreference = (EditTextPreference) findPreference("volume_preference");
mVolumePreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mVolumePreference, 0, 100));

}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.heyongrui.iflytek.speech.util;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;

/**
* 功能性函数扩展类
*/
public class FucUtil {
/**
* 读取asset目录下文件。
*
* @return content
*/
public static String readFile(Context mContext, String file, String code) {
int len = 0;
byte[] buf = null;
String result = "";
try {
InputStream in = mContext.getAssets().open(file);
len = in.available();
buf = new byte[len];
in.read(buf, 0, len);

result = new String(buf, code);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

/**
* 读取asset目录下音频文件。
*
* @return 二进制文件数据
*/
public static byte[] readAudioFile(Context context, String filename) {
try {
InputStream ins = context.getAssets().open(filename);
byte[] data = new byte[ins.available()];

ins.read(data);
ins.close();

return data;
} catch (IOException e) {
e.printStackTrace();
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.heyongrui.iflytek.speech.util;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

/**
* Json结果解析类
*/
public class JsonParser {

public static String parseIatResult(String json) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);

JSONArray words = joResult.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
// 转写结果词,默认使用第一个结果
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
JSONObject obj = items.getJSONObject(0);
ret.append(obj.getString("w"));
// 如果需要多候选结果,解析数组其他字段
// for(int j = 0; j < items.length(); j++)
// {
// JSONObject obj = items.getJSONObject(j);
// ret.append(obj.getString("w"));
// }
}
} catch (Exception e) {
e.printStackTrace();
}
return ret.toString();
}

public static String parseGrammarResult(String json, String engType) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);

JSONArray words = joResult.getJSONArray("ws");
// 云端和本地结果分情况解析
if ("cloud".equals(engType)) {
for (int i = 0; i < words.length(); i++) {
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
for(int j = 0; j < items.length(); j++)
{
JSONObject obj = items.getJSONObject(j);
if(obj.getString("w").contains("nomatch"))
{
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append("【结果】" + obj.getString("w"));
ret.append("【置信度】" + obj.getInt("sc"));
ret.append("\n");
}
}
} else if ("local".equals(engType)) {
ret.append("【结果】");
for (int i = 0; i < words.length(); i++) {
JSONObject wsItem = words.getJSONObject(i);
JSONArray items = wsItem.getJSONArray("cw");
if ("<contact>".equals(wsItem.getString("slot"))) {
// 可能会有多个联系人供选择,用中括号括起来,这些候选项具有相同的置信度
ret.append("【");
for(int j = 0; j < items.length(); j++)
{
JSONObject obj = items.getJSONObject(j);
if(obj.getString("w").contains("nomatch"))
{
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append(obj.getString("w")).append("|");
}
ret.setCharAt(ret.length() - 1, '】');
} else {
//本地多候选按照置信度高低排序,一般选取第一个结果即可
JSONObject obj = items.getJSONObject(0);
if(obj.getString("w").contains("nomatch"))
{
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append(obj.getString("w"));
}
}
ret.append("【置信度】" + joResult.getInt("sc"));
ret.append("\n");
}

} catch (Exception e) {
e.printStackTrace();
ret.append("没有匹配结果.");
}
return ret.toString();
}

public static String parseGrammarResult(String json) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);

JSONArray words = joResult.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
for(int j = 0; j < items.length(); j++)
{
JSONObject obj = items.getJSONObject(j);
if(obj.getString("w").contains("nomatch"))
{
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append("【结果】" + obj.getString("w"));
ret.append("【置信度】" + obj.getInt("sc"));
ret.append("\n");
}
}
} catch (Exception e) {
e.printStackTrace();
ret.append("没有匹配结果.");
}
return ret.toString();
}

public static String parseTransResult(String json, String key) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);
String errorCode = joResult.optString("ret");
if(!errorCode.equals("0")) {
return joResult.optString("errmsg");
}
JSONObject transResult = joResult.optJSONObject("trans_result");
ret.append(transResult.optString(key));
} catch (Exception e) {
e.printStackTrace();
}
return ret.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.heyongrui.iflytek.speech.util;

import android.content.Context;
import android.preference.EditTextPreference;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Toast;

import java.util.regex.Pattern;

/**
* 输入框输入范围控制
*/
public class SettingTextWatcher implements TextWatcher {
private int editStart ;
private int editCount ;
private EditTextPreference mEditTextPreference;
int minValue;//最小值
int maxValue;//最大值
private Context mContext;

public SettingTextWatcher(Context context, EditTextPreference e, int min, int max) {
mContext = context;
mEditTextPreference = e;
minValue = min;
maxValue = max;
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Log.e("demo", "onTextChanged start:"+start+" count:"+count+" before:"+before);
editStart = start;
editCount = count;
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Log.e("demo", "beforeTextChanged start:"+start+" count:"+count+" after:"+after);
}

@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s)) {
return;
}
String content = s.toString();
// Log.e("demo", "content:"+content);
if (isNumeric(content)) {
int num = Integer.parseInt(content);
if (num > maxValue || num < minValue) {
s.delete(editStart, editStart+editCount);
mEditTextPreference.getEditText().setText(s);
Toast.makeText(mContext, "超出有效值范围", Toast.LENGTH_SHORT).show();
}
}else {
s.delete(editStart, editStart+editCount);
mEditTextPreference.getEditText().setText(s);
Toast.makeText(mContext, "只能输入数字哦", Toast.LENGTH_SHORT).show();
}
}

/**
* 正则表达式-判断是否为数字
*/
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.heyongrui.iflytek.speech.util;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

/**
* Xml结果解析类
*/
public class XmlParser {

public static String parseNluResult(String xml)
{
StringBuffer buffer = new StringBuffer();
try
{
// DOM builder
DocumentBuilder domBuilder = null;
// DOM doc
Document domDoc = null;

// init DOM
DocumentBuilderFactory domFact = DocumentBuilderFactory.newInstance();
domBuilder = domFact.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(xml.getBytes());
domDoc = domBuilder.parse(is);

// 获取根节点
Element root = (Element) domDoc.getDocumentElement();

Element raw = (Element)root.getElementsByTagName("rawtext").item(0);
buffer.append("【识别结果】" + raw.getFirstChild().getNodeValue());
buffer.append("\n");

Element e = (Element)root.getElementsByTagName("result").item(0);

Element focus = (Element)e.getElementsByTagName("focus").item(0);
buffer.append("【FOCUS】" + focus.getFirstChild().getNodeValue());
buffer.append("\n");

Element action = (Element)e.getElementsByTagName("action").item(0);
Element operation = (Element)action.getElementsByTagName("operation").item(0);
buffer.append("【ACTION】" + operation.getFirstChild().getNodeValue());
buffer.append("\n");


}catch(Exception e){
e.printStackTrace();
};
buffer.append("【ALL】" + xml);
return buffer.toString();
}
}
Binary file added iflytek/src/main/jniLibs/arm64-v8a/libmsc.so
Binary file not shown.
Binary file added iflytek/src/main/jniLibs/armeabi-v7a/libmsc.so
Binary file not shown.
Binary file added iflytek/src/main/res/drawable-xhdpi/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/btn_left_f.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/btn_left_n.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/cancel.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/cancel_p.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/editbox.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/login_p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/mic_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/mic_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/mic_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/mic_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/name_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added iflytek/src/main/res/drawable-xhdpi/ok.9.png
Binary file added iflytek/src/main/res/drawable-xhdpi/ok_d.9.png
Binary file added iflytek/src/main/res/drawable-xhdpi/ok_p.9.png
Binary file added iflytek/src/main/res/drawable-xhdpi/pane_bg.9.png
Binary file added iflytek/src/main/res/drawable-xhdpi/setting.png
Binary file added iflytek/src/main/res/drawable-xhdpi/setting_p.png
8 changes: 8 additions & 0 deletions iflytek/src/main/res/drawable/btn_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_left_p"/>
<item android:state_focused="true"
android:drawable="@drawable/btn_left_f"/>
<item android:drawable="@drawable/btn_left_n" />
</selector>
8 changes: 8 additions & 0 deletions iflytek/src/main/res/drawable/btn_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_right_p"/>
<item android:state_focused="true"
android:drawable="@drawable/btn_right_f"/>
<item android:drawable="@drawable/btn_right_n" />
</selector>
7 changes: 7 additions & 0 deletions iflytek/src/main/res/drawable/button_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/login_p" />
<item android:state_enabled="false" android:drawable="@drawable/login" />
<item android:drawable="@drawable/login" />
</selector>
17 changes: 17 additions & 0 deletions iflytek/src/main/res/drawable/cancel_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/cancel"/>
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/cancel_p"/>
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/cancel_p"/>
<item
android:drawable="@drawable/cancel"></item>
</selector>
74 changes: 74 additions & 0 deletions iflytek/src/main/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>
6 changes: 6 additions & 0 deletions iflytek/src/main/res/drawable/list_bg_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/list_backgroud_color"></item>
<item android:drawable="@drawable/layout_backgroud"></item>
</selector>
9 changes: 9 additions & 0 deletions iflytek/src/main/res/drawable/main_setting_btn_np.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/setting" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/setting_p" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/setting_p" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/setting"></item>

</selector>
21 changes: 21 additions & 0 deletions iflytek/src/main/res/drawable/ok_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_enabled="false"
android:drawable="@drawable/ok_d"></item>
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/ok"/>
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/ok_p"/>
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/ok_p"/>
<item
android:drawable="@drawable/ok"></item>

</selector>
141 changes: 141 additions & 0 deletions iflytek/src/main/res/layout/iatdemo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="讯飞听写示例"
android:textSize="30sp" />

<ImageButton
android:id="@+id/image_iat_set"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/main_setting_btn_np" />
</RelativeLayout>

<EditText
android:id="@+id/iat_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top|left"
android:paddingBottom="20dp"
android:textSize="20sp" />


<RadioGroup
android:id="@+id/iat_radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="识别类型"
android:orientation="horizontal" >

<RadioButton
android:id="@+id/iat_radioCloud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="云端" >
</RadioButton>

<RadioButton
android:id="@+id/iat_radioLocal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="本地" >
</RadioButton>

</RadioGroup>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >

<Button
android:id="@+id/iat_recognize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="开始"
android:textSize="20sp" />

<Button
android:id="@+id/iat_stop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="停止"
android:textSize="20sp" />

<Button
android:id="@+id/iat_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消"
android:textSize="20sp" />
</LinearLayout>

<Button
android:id="@+id/iat_recognize_stream"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="音频流识别"
android:textSize="20sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="上传联系人、词表,可以使云端识别联系人和词表更加准确,这里上传的内容对语义理解同样有效。"
android:textSize="@dimen/txt_size" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >

<Button
android:id="@+id/iat_upload_contacts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="上传联系人"
android:textSize="17sp" />

<Button
android:id="@+id/iat_upload_userwords"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="上传词表"
android:textSize="17sp" />
</LinearLayout>

</LinearLayout>
115 changes: 115 additions & 0 deletions iflytek/src/main/res/layout/isrdemo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dip" >

<include layout="@layout/title" />

<EditText
android:id="@+id/isr_text"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="top|left"
android:textSize="20sp" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="识别类型"
android:orientation="horizontal" >

<RadioButton
android:id="@+id/radioCloud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="云端" >
</RadioButton>

<RadioButton
android:id="@+id/radioLocal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="本地" >
</RadioButton>

</RadioGroup>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:layout_marginBottom="2dip"
android:gravity="center_horizontal"
android:orientation="horizontal" >

<Button
android:id="@+id/isr_grammar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="构建语法"
android:textSize="20sp"/>
<Button
android:id="@+id/isr_lexcion"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="更新词典"
android:textSize="20sp"
android:enabled="false" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:layout_marginBottom="2dip"
android:gravity="center_horizontal"
android:orientation="horizontal" >

<Button
android:id="@+id/isr_recognize"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="开始识别"
android:textSize="20sp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="2dip"
android:gravity="center_horizontal"
android:orientation="horizontal" >

<Button
android:id="@+id/isr_stop"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="停止录音"
android:textSize="20sp" />

<Button
android:id="@+id/isr_cancel"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消"
android:textSize="20sp" />
</LinearLayout>

</LinearLayout>
56 changes: 56 additions & 0 deletions iflytek/src/main/res/layout/ivw_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:gravity="center">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:gravity="center_horizontal"
android:text="讯飞语音唤醒示例"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/example_explain_wake"
android:textSize="20sp"/>

</LinearLayout>

<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/btn_wake"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="唤醒"
android:textSize="18sp"/>

<Button
android:id="@+id/btn_oneshot"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="唤醒+识别"
android:textSize="18sp"/>

</LinearLayout>

</LinearLayout>
20 changes: 20 additions & 0 deletions iflytek/src/main/res/layout/list_items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_bg_color"
android:descendantFocusability="blocksDescendants"
>

<Button android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:layout_marginLeft="@dimen/margin_"
android:layout_marginRight="@dimen/margin_"
android:layout_marginTop="@dimen/pading_"
android:layout_marginBottom="@dimen/pading_"
android:paddingTop="@dimen/pading_"
android:textSize="@dimen/btn_size"/>
</LinearLayout>
27 changes: 27 additions & 0 deletions iflytek/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/layout_backgroud"
android:orientation="vertical">

<include layout="@layout/title" />

<TextView
android:id="@+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_"
android:text="@string/example_explain"
android:textSize="@dimen/txt_size" />

<ListView
android:id="@+id/listview_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:cacheColorHint="@color/white"
android:divider="@drawable/line_background"
android:dividerHeight="@dimen/line_height"
android:paddingBottom="10dp" />
</LinearLayout>
137 changes: 137 additions & 0 deletions iflytek/src/main/res/layout/oneshot_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:gravity="center">

<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="30sp"
android:gravity="center_horizontal"
android:text="唤醒+识别示例"/>

</LinearLayout>

<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/oneshot_demo_hint"
android:textSize="18sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/oneshot_resource_hint"
android:layout_gravity="left"
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dip">

<TextView
android:id="@+id/txt_thresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="门限值:"
android:textSize="18sp" />

<SeekBar
android:id="@+id/seekBar_thresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dip">

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="识别类型"
android:orientation="horizontal">

<RadioButton
android:id="@+id/radioCloud"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="云端" >
</RadioButton>

<RadioButton
android:id="@+id/radioLocal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="本地" >
</RadioButton>

</RadioGroup>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dip">

<Button
android:id="@+id/btn_grammar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="构建语法" />

<Button
android:id="@+id/btn_oneshot"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="唤醒+识别"/>

<Button
android:id="@+id/btn_stop"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="停止唤醒" />

</LinearLayout>


<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp" >

<TextView
android:id="@+id/txt_show_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp" />
</ScrollView>

</LinearLayout>
16 changes: 16 additions & 0 deletions iflytek/src/main/res/layout/title.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="center">
<TextView
android:text="@string/app_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="30sp"
android:layout_margin="10dip"
/>
</LinearLayout>
Loading

0 comments on commit 534f946

Please sign in to comment.