@ -0,0 +1 @@
|
|||||||
|
Subproject commit 013c5b7b86275a1f98bcd9e1ab0412c78b36a3e7
|
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 7.7 KiB |
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ifly_mnotice_image_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -0,0 +1,39 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 30
|
||||||
|
buildToolsVersion "30.0.3"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "com.iflytek.mscv5plusdemo"
|
||||||
|
minSdkVersion 16
|
||||||
|
targetSdkVersion 30
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
jniLibs.srcDirs = ['libs']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation files('libs/Msc.jar')
|
||||||
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<lint></lint>
|
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.iflytek.mscv5plusdemo"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:icon="@drawable/icon"
|
||||||
|
android:name="SpeechApp"
|
||||||
|
android:label="讯飞语音示例v5+">
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.MainActivity"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:icon="@drawable/icon"
|
||||||
|
android:label="讯飞语音示例v5+"
|
||||||
|
android:screenOrientation="portrait">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity android:name="com.iflytek.speech.setting.TtsSettings"/>
|
||||||
|
<activity android:name="com.iflytek.speech.setting.IatSettings"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.IatDemo"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.AsrDemo"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.TtsDemo"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.IvwActivity"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.WakeDemo"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
<activity
|
||||||
|
android:name="com.iflytek.mscv5plusdemo.OneShotDemo"
|
||||||
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
@ -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>:给;
|
@ -0,0 +1,8 @@
|
|||||||
|
#ABNF 1.0 UTF-8;
|
||||||
|
language zh-CN;
|
||||||
|
mode voice;
|
||||||
|
|
||||||
|
root $main;
|
||||||
|
$main = $place1 到 $place2;
|
||||||
|
$place1 = 北京|武汉|南京|天津|东京;
|
||||||
|
$place2 = 上海|合肥;
|
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 7.7 KiB |
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ifly_mnotice_image_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -0,0 +1 @@
|
|||||||
|
{"userword":[{"name":"我的常用词","words":["佳晨实业","蜀南庭苑","高兰路","复联二"]},{"name":"我的好友","words":["李馨琪","鹿晓雷","张集栋","周家莉","叶震珂","熊泽萌"]}]}
|
@ -0,0 +1,8 @@
|
|||||||
|
#BNF+IAT 1.0 UTF-8;
|
||||||
|
!grammar wake;
|
||||||
|
!slot <callCmd>;
|
||||||
|
!slot <contact>;
|
||||||
|
!start <callStart>;
|
||||||
|
<callStart>:[<callCmd>]<callName>;
|
||||||
|
<callCmd>:讯飞语音|讯飞语点|叮咚叮咚;
|
||||||
|
<callName>:张三|李四|张海洋;
|
@ -0,0 +1,8 @@
|
|||||||
|
#ABNF 1.0 UTF-8;
|
||||||
|
language zh-CN;
|
||||||
|
mode voice;
|
||||||
|
|
||||||
|
root $main;
|
||||||
|
$main = [$call] $name;
|
||||||
|
$call = 讯飞语音|讯飞语点|叮咚叮咚;
|
||||||
|
$name = 张三|李四|张海洋;
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.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.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;
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.btn_wake:
|
||||||
|
intent = new Intent(IvwActivity.this, WakeDemo.class);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.btn_oneshot:
|
||||||
|
intent = new Intent(IvwActivity.this, OneShotDemo.class);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.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.iflytek.mscv5plusdemo.R;
|
||||||
|
import com.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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.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.iflytek.mscv5plusdemo.R;
|
||||||
|
import com.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,173 @@
|
|||||||
|
package com.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 parseLocalGrammarResult(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("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.append("【置信度】" + joResult.optInt("sc"));
|
||||||
|
|
||||||
|
} 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));
|
||||||
|
/*JSONArray words = joResult.getJSONArray("results");
|
||||||
|
for (int i = 0; i < words.length(); i++) {
|
||||||
|
JSONObject obj = words.getJSONObject(i);
|
||||||
|
ret.append(obj.getString(key));
|
||||||
|
}*/
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return ret.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.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();
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 9.6 KiB |
@ -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="@drawable/btn_left_p" />
|
||||||
|
<item android:state_focused="true" android:drawable="@drawable/btn_left_f" />
|
||||||
|
<item android:drawable="@drawable/btn_left_n" />
|
||||||
|
</selector>
|
After Width: | Height: | Size: 702 B |
After Width: | Height: | Size: 945 B |
After Width: | Height: | Size: 1.0 KiB |
@ -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="@drawable/btn_right_p" />
|
||||||
|
<item android:state_focused="true" android:drawable="@drawable/btn_right_f" />
|
||||||
|
<item android:drawable="@drawable/btn_right_n" />
|
||||||
|
</selector>
|
After Width: | Height: | Size: 685 B |
After Width: | Height: | Size: 928 B |
After Width: | Height: | Size: 1.0 KiB |
@ -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="@drawable/login_p" />
|
||||||
|
<item android:state_enabled="false" android:drawable="@drawable/login" />
|
||||||
|
<item android:drawable="@drawable/login" />
|
||||||
|
</selector>
|
After Width: | Height: | Size: 125 B |
After Width: | Height: | Size: 125 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 660 B |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 634 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 122 B |
After Width: | Height: | Size: 126 B |
After Width: | Height: | Size: 122 B |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 33 KiB |