滨化讯飞插件
This commit is contained in:
parent
f46962da29
commit
5e5aed2682
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,14 +1,13 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 30
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion "30.0.3"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.iflytek.voicedemo"
|
applicationId "com.iflytek.voicedemo"
|
||||||
minSdkVersion 9
|
minSdkVersion 16
|
||||||
targetSdkVersion 28
|
targetSdkVersion 30
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@ -26,17 +25,15 @@ android {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile files('libs/Msc.jar')
|
implementation files('libs/Msc.jar')
|
||||||
// compile project(':MscLibSrc')
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
compile 'com.android.support:support-v4:23.+'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,2 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<lint>
|
<lint></lint>
|
||||||
</lint>
|
|
@ -4,10 +4,25 @@
|
|||||||
android:versionCode="1"
|
android:versionCode="1"
|
||||||
android:versionName="2.0.1018.1013">
|
android:versionName="2.0.1018.1013">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@drawable/icon"
|
android:icon="@drawable/icon"
|
||||||
android:name="SpeechApp"
|
android:name="SpeechApp"
|
||||||
android:label="讯飞语音示例">
|
android:label="讯飞语音示例">
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="com.iflytek.voicedemo.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.MainActivity"
|
android:name="com.iflytek.voicedemo.MainActivity"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
@ -20,70 +35,48 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="com.iflytek.speech.setting.TtsSettings" >
|
<activity android:name="com.iflytek.speech.setting.TtsSettings" />
|
||||||
</activity>
|
<activity android:name="com.iflytek.speech.setting.IatSettings" />
|
||||||
<activity android:name="com.iflytek.speech.setting.IatSettings" >
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.IatDemo"
|
android:name="com.iflytek.voicedemo.IatDemo"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.AsrDemo"
|
android:name="com.iflytek.voicedemo.AsrDemo"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.TtsDemo"
|
android:name="com.iflytek.voicedemo.TtsDemo"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.IseDemo"
|
android:name="com.iflytek.voicedemo.IseDemo"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name="com.iflytek.voicedemo.vocalverify.VocalVerifyDemo"
|
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
|
||||||
android:screenOrientation="portrait" >
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.faceonline.OnlineFaceDemo"
|
android:name="com.iflytek.voicedemo.faceonline.OnlineFaceDemo"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity"
|
android:name="com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.IdentifyGroup.FaceIdentifyActivity"
|
android:name="com.iflytek.voicedemo.IdentifyGroup.FaceIdentifyActivity"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name="com.iflytek.voicedemo.IdentifyGroup.VocalIdentifyActivity"
|
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
|
||||||
android:screenOrientation="portrait">
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.voicedemo.IdentifyGroup.ResultIdentifyActivity"
|
android:name="com.iflytek.voicedemo.IdentifyGroup.ResultIdentifyActivity"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.speech.setting.IseSettings"
|
android:name="com.iflytek.speech.setting.IseSettings"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.iflytek.speech.setting.UrlSettings"
|
android:name="com.iflytek.speech.setting.UrlSettings"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" />
|
||||||
</activity>
|
|
||||||
<!-- 移动统计分析 -->
|
<!-- 移动统计分析 -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="IFLYTEK_APPKEY"
|
android:name="IFLYTEK_APPKEY"
|
||||||
@ -95,20 +88,4 @@
|
|||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="8" />
|
|
||||||
|
|
||||||
<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.WRITE_SETTINGS" />
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -3,10 +3,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.iflytek.ise.result;
|
package com.iflytek.ise.result;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.iflytek.ise.result.entity.Sentence;
|
import com.iflytek.ise.result.entity.Sentence;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title: Result</p>
|
* <p>Title: Result</p>
|
||||||
* <p>Description: 评测结果</p>
|
* <p>Description: 评测结果</p>
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.iflytek.ise.result.util;
|
package com.iflytek.ise.result.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.iflytek.ise.result.entity.Phone;
|
import com.iflytek.ise.result.entity.Phone;
|
||||||
import com.iflytek.ise.result.entity.Sentence;
|
import com.iflytek.ise.result.entity.Sentence;
|
||||||
import com.iflytek.ise.result.entity.Syll;
|
import com.iflytek.ise.result.entity.Syll;
|
||||||
import com.iflytek.ise.result.entity.Word;
|
import com.iflytek.ise.result.entity.Word;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title: ResultFormatUtl</p>
|
* <p>Title: ResultFormatUtl</p>
|
||||||
* <p>Description: </p>
|
* <p>Description: </p>
|
||||||
|
@ -3,14 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.iflytek.ise.result.xml;
|
package com.iflytek.ise.result.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
@ -24,6 +16,14 @@ import com.iflytek.ise.result.entity.Sentence;
|
|||||||
import com.iflytek.ise.result.entity.Syll;
|
import com.iflytek.ise.result.entity.Syll;
|
||||||
import com.iflytek.ise.result.entity.Word;
|
import com.iflytek.ise.result.entity.Word;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title: XmlResultParser</p>
|
* <p>Title: XmlResultParser</p>
|
||||||
* <p>Description: </p>
|
* <p>Description: </p>
|
||||||
|
@ -32,6 +32,7 @@ public class IatSettings extends PreferenceActivity implements OnPreferenceChang
|
|||||||
mVadeosPreference = (EditTextPreference) findPreference("iat_vadeos_preference");
|
mVadeosPreference = (EditTextPreference) findPreference("iat_vadeos_preference");
|
||||||
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadeosPreference, 0, 10000));
|
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadeosPreference, 0, 10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -7,8 +7,8 @@ import android.os.Bundle;
|
|||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@ -17,6 +17,8 @@ import android.widget.Toast;
|
|||||||
import com.iflytek.cloud.SpeechConstant;
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
import com.iflytek.voicedemo.R;
|
import com.iflytek.voicedemo.R;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评测设置界面
|
* 评测设置界面
|
||||||
*/
|
*/
|
||||||
@ -32,6 +34,9 @@ public class IseSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
|
|
||||||
|
private HashMap<String, String> zhMap = new HashMap<>();
|
||||||
|
private HashMap<String, String> enMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
@ -39,10 +44,27 @@ public class IseSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
||||||
addPreferencesFromResource(R.xml.ise_settings);
|
addPreferencesFromResource(R.xml.ise_settings);
|
||||||
|
initCategoryMap();
|
||||||
initUI();
|
initUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initCategoryMap() {
|
||||||
|
zhMap.put("read_syllable", "单字");
|
||||||
|
zhMap.put("read_word", "词语");
|
||||||
|
zhMap.put("read_sentence", "句子");
|
||||||
|
zhMap.put("read_chapter", "篇章");
|
||||||
|
|
||||||
|
enMap.put("read_word", "词语");
|
||||||
|
enMap.put("read_sentence", "句子");
|
||||||
|
enMap.put("read_chapter", "篇章");
|
||||||
|
enMap.put("simple_expression", "英文情景反应");
|
||||||
|
enMap.put("read_choice", "英文选择题");
|
||||||
|
enMap.put("topic", "英文自由题");
|
||||||
|
enMap.put("retell", "英文复述题");
|
||||||
|
enMap.put("picture_talk", "英文看图说话");
|
||||||
|
enMap.put("oral_translation", "英文口头翻译");
|
||||||
|
}
|
||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE);
|
mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE);
|
||||||
mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY);
|
mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY);
|
||||||
@ -70,14 +92,23 @@ public class IseSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
|
||||||
|
String categoryValue = mCategoryPref.getValue();
|
||||||
|
|
||||||
if ("zh_cn".equals(newValue.toString())) {
|
if ("zh_cn".equals(newValue.toString())) {
|
||||||
|
// 中文
|
||||||
if ("plain".equals(mResultLevelPref.getValue())) {
|
if ("plain".equals(mResultLevelPref.getValue())) {
|
||||||
showTip("汉语评测结果格式不支持plain设置");
|
showTip("汉语评测结果格式不支持plain设置");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!zhMap.containsKey(categoryValue)) {
|
||||||
|
showTip("中文评测不支持" + enMap.get(categoryValue));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ("read_syllable".equals(mCategoryPref.getValue())) {
|
// 英文
|
||||||
showTip("英语评测不支持单字");
|
if (!enMap.containsKey(categoryValue)) {
|
||||||
|
showTip("英语评测不支持" + zhMap.get(categoryValue));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,10 +124,20 @@ public class IseSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if ("en_us".equals(mLanguagePref.getValue()) && "read_syllable".equals(newValue.toString())) {
|
String categoryValue = newValue.toString();
|
||||||
showTip("英语评测不支持单字,请选其他项");
|
|
||||||
|
if ("en_us".equals(mLanguagePref.getValue())) {
|
||||||
|
if (!enMap.containsKey(categoryValue)) {
|
||||||
|
showTip("英语评测不支持" + zhMap.get(categoryValue) + ",请选其他项");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ("zh_cn".equals(mLanguagePref.getValue())) {
|
||||||
|
if (!zhMap.containsKey(categoryValue)) {
|
||||||
|
showTip("中文评测不支持" + enMap.get(categoryValue) + ",请选其他项");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString());
|
int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString());
|
||||||
String newEntry = (String) mCategoryPref.getEntries()[newValueIndex];
|
String newEntry = (String) mCategoryPref.getEntries()[newValueIndex];
|
||||||
@ -194,6 +235,7 @@ public class IseSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
private void showTip(String str) {
|
private void showTip(String str) {
|
||||||
if (!TextUtils.isEmpty(str)) {
|
if (!TextUtils.isEmpty(str)) {
|
||||||
|
mToast.cancel();
|
||||||
mToast.setText(str);
|
mToast.setText(str);
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
package com.iflytek.speech.setting;
|
package com.iflytek.speech.setting;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
import androidx.annotation.Nullable;
|
||||||
import com.iflytek.voicedemo.R;
|
|
||||||
|
|
||||||
import java.util.List;
|
import com.iflytek.voicedemo.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hjyu
|
* @author hjyu
|
||||||
|
@ -3,6 +3,8 @@ package com.iflytek.speech.util;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -13,14 +15,17 @@ import android.graphics.Point;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.media.ExifInterface;
|
import android.media.ExifInterface;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Build;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class FaceUtil {
|
public class FaceUtil {
|
||||||
@ -28,6 +33,19 @@ public class FaceUtil {
|
|||||||
public final static int REQUEST_CAMERA_IMAGE = 2;
|
public final static int REQUEST_CAMERA_IMAGE = 2;
|
||||||
public final static int REQUEST_CROP_IMAGE = 3;
|
public final static int REQUEST_CROP_IMAGE = 3;
|
||||||
|
|
||||||
|
|
||||||
|
public static Uri parseUri(Context context, File file) {
|
||||||
|
Uri imageUri = Uri.fromFile(file);
|
||||||
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
|
imageUri = FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
context.getPackageName() + ".fileprovider",
|
||||||
|
file
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return imageUri;
|
||||||
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 裁剪图片
|
* 裁剪图片
|
||||||
* @param activity Activity
|
* @param activity Activity
|
||||||
@ -41,35 +59,40 @@ public class FaceUtil {
|
|||||||
innerIntent.putExtra("aspectY", 1);// 放大缩小比例的X 这里的比例为: 1:1
|
innerIntent.putExtra("aspectY", 1);// 放大缩小比例的X 这里的比例为: 1:1
|
||||||
innerIntent.putExtra("outputX", 320); //这个是限制输出图片大小
|
innerIntent.putExtra("outputX", 320); //这个是限制输出图片大小
|
||||||
innerIntent.putExtra("outputY", 320);
|
innerIntent.putExtra("outputY", 320);
|
||||||
innerIntent.putExtra("return-data", true);
|
innerIntent.putExtra("return-data", false);
|
||||||
// 切图大小不足输出,无黑框
|
// 切图大小不足输出,无黑框
|
||||||
innerIntent.putExtra("scale", true);
|
innerIntent.putExtra("scale", true);
|
||||||
innerIntent.putExtra("scaleUpIfNeeded", true);
|
innerIntent.putExtra("scaleUpIfNeeded", true);
|
||||||
File imageFile = new File(getImagePath(activity.getApplicationContext()));
|
File imageFile = new File(getImagePath(activity.getApplicationContext()));
|
||||||
innerIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
|
imageFile.delete();
|
||||||
|
Uri cropUri = parseUri(activity, imageFile);
|
||||||
|
innerIntent.putExtra(MediaStore.EXTRA_OUTPUT, cropUri);
|
||||||
innerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
|
innerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
|
||||||
|
|
||||||
|
List<ResolveInfo> resolveInfos = activity.getPackageManager()
|
||||||
|
.queryIntentActivities(innerIntent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
for (ResolveInfo resolveInfo : resolveInfos) {
|
||||||
|
activity.grantUriPermission(activity.getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
activity.grantUriPermission(resolveInfo.activityInfo.packageName, cropUri,
|
||||||
|
(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
|
||||||
|
}
|
||||||
|
innerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
innerIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
activity.startActivityForResult(innerIntent, REQUEST_CROP_IMAGE);
|
activity.startActivityForResult(innerIntent, REQUEST_CROP_IMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存裁剪的图片的路径
|
* 保存裁剪的图片的路径
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getImagePath(Context context) {
|
public static String getImagePath(Context context) {
|
||||||
String path;
|
String path = context.getExternalFilesDir("msc").getAbsolutePath();
|
||||||
|
|
||||||
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
||||||
path = context.getFilesDir().getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/msc/";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!path.endsWith("/")) {
|
if (!path.endsWith("/")) {
|
||||||
path += "/";
|
path += "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
File folder = new File(path);
|
File folder = new File(path);
|
||||||
if (folder != null && !folder.exists()) {
|
if (!folder.exists()) {
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
path += "ifd.jpg";
|
path += "ifd.jpg";
|
||||||
@ -172,8 +195,7 @@ public class FaceUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (face.point != null) {
|
if (face.point != null) {
|
||||||
for (Point p : face.point)
|
for (Point p : face.point) {
|
||||||
{
|
|
||||||
if (frontCamera) {
|
if (frontCamera) {
|
||||||
p.y = width - p.y;
|
p.y = width - p.y;
|
||||||
}
|
}
|
||||||
@ -185,17 +207,10 @@ public class FaceUtil {
|
|||||||
/**
|
/**
|
||||||
* 将矩形随原图顺时针旋转90度
|
* 将矩形随原图顺时针旋转90度
|
||||||
*
|
*
|
||||||
* @param r
|
* @param r 待旋转的矩形
|
||||||
* 待旋转的矩形
|
* @param width 输入矩形对应的原图宽
|
||||||
*
|
* @param height 输入矩形对应的原图高
|
||||||
* @param width
|
* @return 旋转后的矩形
|
||||||
* 输入矩形对应的原图宽
|
|
||||||
*
|
|
||||||
* @param height
|
|
||||||
* 输入矩形对应的原图高
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* 旋转后的矩形
|
|
||||||
*/
|
*/
|
||||||
static public Rect RotateDeg90(Rect r, int width, int height) {
|
static public Rect RotateDeg90(Rect r, int width, int height) {
|
||||||
int left = r.left;
|
int left = r.left;
|
||||||
@ -208,17 +223,11 @@ public class FaceUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将点随原图顺时针旋转90度
|
* 将点随原图顺时针旋转90度
|
||||||
* @param p
|
|
||||||
* 待旋转的点
|
|
||||||
*
|
*
|
||||||
* @param width
|
* @param p 待旋转的点
|
||||||
* 输入点对应的原图宽
|
* @param width 输入点对应的原图宽
|
||||||
*
|
* @param height 输入点对应的原图宽
|
||||||
* @param height
|
* @return 旋转后的点
|
||||||
* 输入点对应的原图宽
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* 旋转后的点
|
|
||||||
*/
|
*/
|
||||||
static public Point RotateDeg90(Point p, int width, int height) {
|
static public Point RotateDeg90(Point p, int width, int height) {
|
||||||
int x = p.x;
|
int x = p.x;
|
||||||
@ -249,7 +258,6 @@ public class FaceUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存Bitmap至本地
|
* 保存Bitmap至本地
|
||||||
* @param Bitmap
|
|
||||||
*/
|
*/
|
||||||
public static void saveBitmapToFile(Context context, Bitmap bmp) {
|
public static void saveBitmapToFile(Context context, Bitmap bmp) {
|
||||||
String file_path = getImagePath(context);
|
String file_path = getImagePath(context);
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package com.iflytek.speech.util;
|
package com.iflytek.speech.util;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import android.content.Context;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.iflytek.cloud.ErrorCode;
|
import com.iflytek.cloud.ErrorCode;
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
import com.iflytek.cloud.SpeechUtility;
|
import com.iflytek.cloud.SpeechUtility;
|
||||||
|
|
||||||
import android.content.Context;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能性函数扩展类
|
* 功能性函数扩展类
|
||||||
@ -18,10 +19,10 @@ import android.content.Context;
|
|||||||
public class FucUtil {
|
public class FucUtil {
|
||||||
/**
|
/**
|
||||||
* 读取asset目录下文件。
|
* 读取asset目录下文件。
|
||||||
|
*
|
||||||
* @return content
|
* @return content
|
||||||
*/
|
*/
|
||||||
public static String readFile(Context mContext,String file,String code)
|
public static String readFile(Context mContext, String file, String code) {
|
||||||
{
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
byte[] buf = null;
|
byte[] buf = null;
|
||||||
String result = "";
|
String result = "";
|
||||||
@ -37,30 +38,28 @@ public class FucUtil {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将字节缓冲区按照固定大小进行分割成数组
|
* 将字节缓冲区按照固定大小进行分割成数组
|
||||||
|
*
|
||||||
* @param buffer 缓冲区
|
* @param buffer 缓冲区
|
||||||
* @param length 缓冲区大小
|
* @param length 缓冲区大小
|
||||||
* @param spsize 切割块大小
|
* @param spsize 切割块大小
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ArrayList<byte[]> splitBuffer(byte[] buffer,int length,int spsize)
|
public static ArrayList<byte[]> splitBuffer(byte[] buffer, int length, int spsize) {
|
||||||
{
|
|
||||||
ArrayList<byte[]> array = new ArrayList<byte[]>();
|
ArrayList<byte[]> array = new ArrayList<byte[]>();
|
||||||
if (spsize <= 0 || length <= 0 || buffer == null || buffer.length < length)
|
if (spsize <= 0 || length <= 0 || buffer == null || buffer.length < length)
|
||||||
return array;
|
return array;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while(size < length)
|
while (size < length) {
|
||||||
{
|
|
||||||
int left = length - size;
|
int left = length - size;
|
||||||
if(spsize < left)
|
if (spsize < left) {
|
||||||
{
|
|
||||||
byte[] sdata = new byte[spsize];
|
byte[] sdata = new byte[spsize];
|
||||||
System.arraycopy(buffer, size, sdata, 0, spsize);
|
System.arraycopy(buffer, size, sdata, 0, spsize);
|
||||||
array.add(sdata);
|
array.add(sdata);
|
||||||
size += spsize;
|
size += spsize;
|
||||||
}else
|
} else {
|
||||||
{
|
|
||||||
byte[] sdata = new byte[left];
|
byte[] sdata = new byte[left];
|
||||||
System.arraycopy(buffer, size, sdata, 0, left);
|
System.arraycopy(buffer, size, sdata, 0, left);
|
||||||
array.add(sdata);
|
array.add(sdata);
|
||||||
@ -69,11 +68,12 @@ public class FucUtil {
|
|||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取语记是否包含离线听写资源,如未包含跳转至资源下载页面
|
* 获取语记是否包含离线听写资源,如未包含跳转至资源下载页面
|
||||||
* 1.PLUS_LOCAL_ALL: 本地所有资源
|
* 1.PLUS_LOCAL_ALL: 本地所有资源
|
||||||
2.PLUS_LOCAL_ASR: 本地识别资源
|
* 2.PLUS_LOCAL_ASR: 本地识别资源
|
||||||
3.PLUS_LOCAL_TTS: 本地合成资源
|
* 3.PLUS_LOCAL_TTS: 本地合成资源
|
||||||
*/
|
*/
|
||||||
public static String checkLocalResource() {
|
public static String checkLocalResource() {
|
||||||
String resource = SpeechUtility.getUtility().getParameter(SpeechConstant.PLUS_LOCAL_ASR);
|
String resource = SpeechUtility.getUtility().getParameter(SpeechConstant.PLUS_LOCAL_ASR);
|
||||||
|
@ -4,8 +4,6 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json结果解析类
|
* Json结果解析类
|
||||||
*/
|
*/
|
||||||
@ -36,6 +34,66 @@ public class JsonParser {
|
|||||||
return ret.toString();
|
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) {
|
public static String parseGrammarResult(String json) {
|
||||||
StringBuffer ret = new StringBuffer();
|
StringBuffer ret = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
@ -45,11 +103,9 @@ public class JsonParser {
|
|||||||
JSONArray words = joResult.getJSONArray("ws");
|
JSONArray words = joResult.getJSONArray("ws");
|
||||||
for (int i = 0; i < words.length(); i++) {
|
for (int i = 0; i < words.length(); i++) {
|
||||||
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
||||||
for(int j = 0; j < items.length(); j++)
|
for (int j = 0; j < items.length(); j++) {
|
||||||
{
|
|
||||||
JSONObject obj = items.getJSONObject(j);
|
JSONObject obj = items.getJSONObject(j);
|
||||||
if(obj.getString("w").contains("nomatch"))
|
if (obj.getString("w").contains("nomatch")) {
|
||||||
{
|
|
||||||
ret.append("没有匹配结果.");
|
ret.append("没有匹配结果.");
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
@ -74,11 +130,9 @@ public class JsonParser {
|
|||||||
JSONArray words = joResult.getJSONArray("ws");
|
JSONArray words = joResult.getJSONArray("ws");
|
||||||
for (int i = 0; i < words.length(); i++) {
|
for (int i = 0; i < words.length(); i++) {
|
||||||
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
||||||
for(int j = 0; j < items.length(); j++)
|
for (int j = 0; j < items.length(); j++) {
|
||||||
{
|
|
||||||
JSONObject obj = items.getJSONObject(j);
|
JSONObject obj = items.getJSONObject(j);
|
||||||
if(obj.getString("w").contains("nomatch"))
|
if (obj.getString("w").contains("nomatch")) {
|
||||||
{
|
|
||||||
ret.append("没有匹配结果.");
|
ret.append("没有匹配结果.");
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.iflytek.speech.util;
|
package com.iflytek.speech.util;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -8,6 +7,8 @@ import android.text.TextUtils;
|
|||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入框输入范围控制
|
* 输入框输入范围控制
|
||||||
*/
|
*/
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
package com.iflytek.speech.util;
|
package com.iflytek.speech.util;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
/**
|
/**
|
||||||
* Xml结果解析类
|
* Xml结果解析类
|
||||||
*/
|
*/
|
||||||
public class XmlParser {
|
public class XmlParser {
|
||||||
|
|
||||||
public static String parseNluResult(String xml)
|
public static String parseNluResult(String xml) {
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// DOM builder
|
// DOM builder
|
||||||
DocumentBuilder domBuilder = null;
|
DocumentBuilder domBuilder = null;
|
||||||
// DOM doc
|
// DOM doc
|
||||||
@ -46,11 +45,10 @@ public class XmlParser {
|
|||||||
Element operation = (Element) action.getElementsByTagName("operation").item(0);
|
Element operation = (Element) action.getElementsByTagName("operation").item(0);
|
||||||
buffer.append("【ACTION】" + operation.getFirstChild().getNodeValue());
|
buffer.append("【ACTION】" + operation.getFirstChild().getNodeValue());
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
};
|
}
|
||||||
|
|
||||||
buffer.append("【ALL】" + xml);
|
buffer.append("【ALL】" + xml);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,17 @@ import android.app.Activity;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioGroup;
|
|
||||||
import android.widget.RadioGroup.OnCheckedChangeListener;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.iflytek.cloud.ErrorCode;
|
import com.iflytek.cloud.ErrorCode;
|
||||||
import com.iflytek.cloud.GrammarListener;
|
import com.iflytek.cloud.GrammarListener;
|
||||||
import com.iflytek.cloud.InitListener;
|
import com.iflytek.cloud.InitListener;
|
||||||
import com.iflytek.cloud.LexiconListener;
|
|
||||||
import com.iflytek.cloud.RecognizerListener;
|
import com.iflytek.cloud.RecognizerListener;
|
||||||
import com.iflytek.cloud.RecognizerResult;
|
import com.iflytek.cloud.RecognizerResult;
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
@ -27,7 +23,6 @@ import com.iflytek.cloud.SpeechError;
|
|||||||
import com.iflytek.cloud.SpeechRecognizer;
|
import com.iflytek.cloud.SpeechRecognizer;
|
||||||
import com.iflytek.speech.util.FucUtil;
|
import com.iflytek.speech.util.FucUtil;
|
||||||
import com.iflytek.speech.util.JsonParser;
|
import com.iflytek.speech.util.JsonParser;
|
||||||
/*import com.iflytek.sunflower.FlowerCollector;*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 识别示例
|
* 识别示例
|
||||||
@ -60,8 +55,6 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
mCloudGrammar = FucUtil.readFile(this, "grammar_sample.abnf", "utf-8");
|
mCloudGrammar = FucUtil.readFile(this, "grammar_sample.abnf", "utf-8");
|
||||||
|
|
||||||
mSharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
mSharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
||||||
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,9 +69,9 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 语法、词典临时变量
|
// 语法、词典临时变量
|
||||||
String mContent;
|
private String mContent;
|
||||||
// 函数调用返回值
|
// 函数调用返回值
|
||||||
int ret = 0;
|
private int ret = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@ -92,8 +85,7 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
showTip("请先选择识别引擎类型");
|
showTip("请先选择识别引擎类型");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch(view.getId())
|
switch (view.getId()) {
|
||||||
{
|
|
||||||
case R.id.isr_grammar:
|
case R.id.isr_grammar:
|
||||||
showTip("上传预设关键词/语法文件");
|
showTip("上传预设关键词/语法文件");
|
||||||
// 在线-构建语法文件,生成语法id
|
// 在线-构建语法文件,生成语法id
|
||||||
@ -103,9 +95,9 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
|
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
|
||||||
mAsr.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
mAsr.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
||||||
ret = mAsr.buildGrammar(GRAMMAR_TYPE_ABNF, mContent, mCloudGrammarListener);
|
ret = mAsr.buildGrammar(GRAMMAR_TYPE_ABNF, mContent, mCloudGrammarListener);
|
||||||
if(ret != ErrorCode.SUCCESS)
|
if (ret != ErrorCode.SUCCESS) {
|
||||||
showTip("语法构建失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
showTip("语法构建失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
// 开始识别
|
// 开始识别
|
||||||
case R.id.isr_recognize:
|
case R.id.isr_recognize:
|
||||||
@ -114,8 +106,7 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
if (!setParam()) {
|
if (!setParam()) {
|
||||||
showTip("请先构建语法。");
|
showTip("请先构建语法。");
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
ret = mAsr.startListening(mRecognizerListener);
|
ret = mAsr.startListening(mRecognizerListener);
|
||||||
if (ret != ErrorCode.SUCCESS) {
|
if (ret != ErrorCode.SUCCESS) {
|
||||||
showTip("识别失败,错误码: " + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
showTip("识别失败,错误码: " + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||||
@ -148,20 +139,6 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新词典监听器。
|
|
||||||
*/
|
|
||||||
private LexiconListener mLexiconListener = new LexiconListener() {
|
|
||||||
@Override
|
|
||||||
public void onLexiconUpdated(String lexiconId, SpeechError error) {
|
|
||||||
if(error == null){
|
|
||||||
showTip("词典更新成功");
|
|
||||||
}else{
|
|
||||||
showTip("词典更新失败,错误码:"+error.getErrorCode()+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 云端构建语法监听器。
|
* 云端构建语法监听器。
|
||||||
*/
|
*/
|
||||||
@ -240,12 +217,14 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void showTip(final String str) {
|
private void showTip(final String str) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mToast.setText(str);
|
if (mToast != null) {
|
||||||
|
mToast.cancel();
|
||||||
|
}
|
||||||
|
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -253,6 +232,7 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数设置
|
* 参数设置
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean setParam() {
|
public boolean setParam() {
|
||||||
@ -262,11 +242,9 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
//设置返回结果为json格式
|
//设置返回结果为json格式
|
||||||
mAsr.setParameter(SpeechConstant.RESULT_TYPE, "json");
|
mAsr.setParameter(SpeechConstant.RESULT_TYPE, "json");
|
||||||
|
|
||||||
if("cloud".equalsIgnoreCase(mEngineType))
|
if ("cloud".equalsIgnoreCase(mEngineType)) {
|
||||||
{
|
|
||||||
String grammarId = mSharedPreferences.getString(KEY_GRAMMAR_ABNF_ID, null);
|
String grammarId = mSharedPreferences.getString(KEY_GRAMMAR_ABNF_ID, null);
|
||||||
if(TextUtils.isEmpty(grammarId))
|
if (TextUtils.isEmpty(grammarId)) {
|
||||||
{
|
|
||||||
result = false;
|
result = false;
|
||||||
} else {
|
} else {
|
||||||
//设置云端识别使用的语法id
|
//设置云端识别使用的语法id
|
||||||
@ -274,10 +252,10 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 设置音频保存路径,保存音频格式支持pcm、wav,
|
||||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
|
||||||
mAsr.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
mAsr.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
||||||
mAsr.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/asr.wav");
|
mAsr.setParameter(SpeechConstant.ASR_AUDIO_PATH,
|
||||||
|
getExternalFilesDir("msc").getAbsolutePath() + "/asr.wav");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,20 +270,4 @@ public class AsrDemo extends Activity implements OnClickListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
//移动数据统计分析
|
|
||||||
/* FlowerCollector.onResume(AsrDemo.this);
|
|
||||||
FlowerCollector.onPageStart(TAG);*/
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
//移动数据统计分析
|
|
||||||
/*FlowerCollector.onPageEnd(TAG);
|
|
||||||
FlowerCollector.onPause(AsrDemo.this);*/
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
package com.iflytek.voicedemo;
|
package com.iflytek.voicedemo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -14,10 +7,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -36,12 +25,17 @@ import com.iflytek.cloud.SpeechError;
|
|||||||
import com.iflytek.cloud.SpeechRecognizer;
|
import com.iflytek.cloud.SpeechRecognizer;
|
||||||
import com.iflytek.cloud.ui.RecognizerDialog;
|
import com.iflytek.cloud.ui.RecognizerDialog;
|
||||||
import com.iflytek.cloud.ui.RecognizerDialogListener;
|
import com.iflytek.cloud.ui.RecognizerDialogListener;
|
||||||
import com.iflytek.cloud.util.ContactManager;
|
|
||||||
import com.iflytek.cloud.util.ContactManager.ContactListener;
|
|
||||||
import com.iflytek.speech.setting.IatSettings;
|
import com.iflytek.speech.setting.IatSettings;
|
||||||
import com.iflytek.speech.util.FucUtil;
|
import com.iflytek.speech.util.FucUtil;
|
||||||
import com.iflytek.speech.util.JsonParser;
|
import com.iflytek.speech.util.JsonParser;
|
||||||
/*import com.iflytek.sunflower.FlowerCollector;*/
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class IatDemo extends Activity implements OnClickListener {
|
public class IatDemo extends Activity implements OnClickListener {
|
||||||
private static String TAG = IatDemo.class.getSimpleName();
|
private static String TAG = IatDemo.class.getSimpleName();
|
||||||
@ -50,7 +44,7 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
// 语音听写UI
|
// 语音听写UI
|
||||||
private RecognizerDialog mIatDialog;
|
private RecognizerDialog mIatDialog;
|
||||||
// 用HashMap存储听写结果
|
// 用HashMap存储听写结果
|
||||||
private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
|
private HashMap<String, String> mIatResults = new LinkedHashMap<>();
|
||||||
|
|
||||||
private EditText mResultText;
|
private EditText mResultText;
|
||||||
private EditText showContacts;
|
private EditText showContacts;
|
||||||
@ -67,24 +61,9 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
private String resultType = "json";
|
private String resultType = "json";
|
||||||
|
|
||||||
private boolean cyclic = false;//音频流识别是否循环调用
|
|
||||||
|
|
||||||
private StringBuffer buffer = new StringBuffer();
|
private StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
Handler han = new Handler(){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
super.handleMessage(msg);
|
|
||||||
if (msg.what == 0x001) {
|
|
||||||
executeStream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static int flg=0;
|
|
||||||
|
|
||||||
@SuppressLint("ShowToast")
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
@ -103,21 +82,17 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
mSharedPreferences = getSharedPreferences(IatSettings.PREFER_NAME,
|
mSharedPreferences = getSharedPreferences(IatSettings.PREFER_NAME,
|
||||||
Activity.MODE_PRIVATE);
|
Activity.MODE_PRIVATE);
|
||||||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
|
|
||||||
mResultText = ((EditText) findViewById(R.id.iat_text));
|
mResultText = ((EditText) findViewById(R.id.iat_text));
|
||||||
showContacts = (EditText) findViewById(R.id.iat_contacts);
|
showContacts = (EditText) findViewById(R.id.iat_contacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化Layout。
|
* 初始化Layout。
|
||||||
*/
|
*/
|
||||||
private void initLayout() {
|
private void initLayout() {
|
||||||
findViewById(R.id.iat_recognize).setOnClickListener(IatDemo.this);
|
findViewById(R.id.iat_recognize).setOnClickListener(IatDemo.this);
|
||||||
findViewById(R.id.iat_recognize_stream).setOnClickListener(IatDemo.this);
|
findViewById(R.id.iat_recognize_stream).setOnClickListener(IatDemo.this);
|
||||||
findViewById(R.id.iat_upload_contacts).setOnClickListener(IatDemo.this);
|
|
||||||
findViewById(R.id.iat_upload_userwords).setOnClickListener(IatDemo.this);
|
findViewById(R.id.iat_upload_userwords).setOnClickListener(IatDemo.this);
|
||||||
findViewById(R.id.iat_stop).setOnClickListener(IatDemo.this);
|
findViewById(R.id.iat_stop).setOnClickListener(IatDemo.this);
|
||||||
findViewById(R.id.iat_cancel).setOnClickListener(IatDemo.this);
|
findViewById(R.id.iat_cancel).setOnClickListener(IatDemo.this);
|
||||||
@ -144,9 +119,6 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
// 开始听写
|
// 开始听写
|
||||||
// 如何判断一次听写结束:OnResult isLast=true 或者 onError
|
// 如何判断一次听写结束:OnResult isLast=true 或者 onError
|
||||||
case R.id.iat_recognize:
|
case R.id.iat_recognize:
|
||||||
// 移动数据分析,收集开始听写事件
|
|
||||||
// FlowerCollector.onEvent(IatDemo.this, "iat_recognize");
|
|
||||||
|
|
||||||
buffer.setLength(0);
|
buffer.setLength(0);
|
||||||
mResultText.setText(null);// 清空显示内容
|
mResultText.setText(null);// 清空显示内容
|
||||||
mIatResults.clear();
|
mIatResults.clear();
|
||||||
@ -186,19 +158,10 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
mIat.cancel();
|
mIat.cancel();
|
||||||
showTip("取消听写");
|
showTip("取消听写");
|
||||||
break;
|
break;
|
||||||
// 上传联系人
|
|
||||||
case R.id.iat_upload_contacts:
|
|
||||||
showTip(getString(R.string.text_upload_contacts));
|
|
||||||
ContactManager mgr = ContactManager.createManager(IatDemo.this,
|
|
||||||
mContactListener);
|
|
||||||
mgr.asyncQueryAllContactsName();
|
|
||||||
break;
|
|
||||||
// 上传用户词表
|
// 上传用户词表
|
||||||
case R.id.iat_upload_userwords:
|
case R.id.iat_upload_userwords:
|
||||||
showTip(getString(R.string.text_upload_userwords));
|
|
||||||
String contents = FucUtil.readFile(IatDemo.this, "userwords", "utf-8");
|
String contents = FucUtil.readFile(IatDemo.this, "userwords", "utf-8");
|
||||||
showContacts.setText(contents);
|
showContacts.setText(contents);
|
||||||
|
|
||||||
// 指定引擎类型
|
// 指定引擎类型
|
||||||
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
|
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
|
||||||
mIat.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
mIat.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
||||||
@ -234,6 +197,7 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
* <item>es_es</item> 西班牙语
|
* <item>es_es</item> 西班牙语
|
||||||
* <item>fr_fr</item> 法语
|
* <item>fr_fr</item> 法语
|
||||||
* <item>ko_kr</item> 韩语
|
* <item>ko_kr</item> 韩语
|
||||||
|
*
|
||||||
* @param v
|
* @param v
|
||||||
*/
|
*/
|
||||||
private void setLanguage(View v) {
|
private void setLanguage(View v) {
|
||||||
@ -282,7 +246,7 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
public void onError(SpeechError error) {
|
public void onError(SpeechError error) {
|
||||||
// Tips:
|
// Tips:
|
||||||
// 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。
|
// 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。
|
||||||
|
Log.d(TAG, "onError " + error.getPlainDescription(true));
|
||||||
showTip(error.getPlainDescription(true));
|
showTip(error.getPlainDescription(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -296,29 +260,23 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onResult(RecognizerResult results, boolean isLast) {
|
public void onResult(RecognizerResult results, boolean isLast) {
|
||||||
Log.d(TAG, results.getResultString());
|
Log.d(TAG, results.getResultString());
|
||||||
System.out.println(flg++);
|
if (isLast) {
|
||||||
|
Log.d(TAG, "onResult 结束");
|
||||||
|
}
|
||||||
if (resultType.equals("json")) {
|
if (resultType.equals("json")) {
|
||||||
|
|
||||||
printResult(results);
|
printResult(results);
|
||||||
|
return;
|
||||||
}else if(resultType.equals("plain")) {
|
}
|
||||||
|
if (resultType.equals("plain")) {
|
||||||
buffer.append(results.getResultString());
|
buffer.append(results.getResultString());
|
||||||
mResultText.setText(buffer.toString());
|
mResultText.setText(buffer.toString());
|
||||||
mResultText.setSelection(mResultText.length());
|
mResultText.setSelection(mResultText.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLast & cyclic) {
|
|
||||||
// TODO 最后的结果
|
|
||||||
Message message = Message.obtain();
|
|
||||||
message.what = 0x001;
|
|
||||||
han.sendMessageDelayed(message,100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVolumeChanged(int volume, byte[] data) {
|
public void onVolumeChanged(int volume, byte[] data) {
|
||||||
showTip("当前正在说话,音量大小:" + volume);
|
showTip("当前正在说话,音量大小 = " + volume + " 返回音频数据 = " + data.length);
|
||||||
Log.d(TAG, "返回音频数据:"+data.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -332,9 +290,11 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示结果
|
||||||
|
*/
|
||||||
private void printResult(RecognizerResult results) {
|
private void printResult(RecognizerResult results) {
|
||||||
String text = JsonParser.parseIatResult(results.getResultString());
|
String text = JsonParser.parseIatResult(results.getResultString());
|
||||||
|
|
||||||
String sn = null;
|
String sn = null;
|
||||||
// 读取json结果中的sn字段
|
// 读取json结果中的sn字段
|
||||||
try {
|
try {
|
||||||
@ -350,7 +310,6 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
for (String key : mIatResults.keySet()) {
|
for (String key : mIatResults.keySet()) {
|
||||||
resultBuffer.append(mIatResults.get(key));
|
resultBuffer.append(mIatResults.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
mResultText.setText(resultBuffer.toString());
|
mResultText.setText(resultBuffer.toString());
|
||||||
mResultText.setSelection(mResultText.length());
|
mResultText.setSelection(mResultText.length());
|
||||||
}
|
}
|
||||||
@ -359,50 +318,24 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
* 听写UI监听器
|
* 听写UI监听器
|
||||||
*/
|
*/
|
||||||
private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() {
|
private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() {
|
||||||
|
// 返回结果
|
||||||
public void onResult(RecognizerResult results, boolean isLast) {
|
public void onResult(RecognizerResult results, boolean isLast) {
|
||||||
|
|
||||||
printResult(results);
|
printResult(results);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 识别回调错误
|
||||||
* 识别回调错误.
|
|
||||||
*/
|
|
||||||
public void onError(SpeechError error) {
|
public void onError(SpeechError error) {
|
||||||
showTip(error.getPlainDescription(true));
|
showTip(error.getPlainDescription(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取联系人监听器。
|
|
||||||
*/
|
|
||||||
private ContactListener mContactListener = new ContactListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onContactQueryFinish(final String contactInfos, boolean changeFlag) {
|
|
||||||
// 注:实际应用中除第一次上传之外,之后应该通过changeFlag判断是否需要上传,否则会造成不必要的流量.
|
|
||||||
// 每当联系人发生变化,该接口都将会被回调,可通过ContactManager.destroy()销毁对象,解除回调。
|
|
||||||
// if(changeFlag) {
|
|
||||||
// 指定引擎类型
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
showContacts.setText(contactInfos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mIat.setParameter(SpeechConstant.ENGINE_TYPE,SpeechConstant.TYPE_CLOUD);
|
|
||||||
mIat.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
|
||||||
ret = mIat.updateLexicon("contact", contactInfos, mLexiconListener);
|
|
||||||
if (ret != ErrorCode.SUCCESS) {
|
|
||||||
showTip("上传联系人失败:" + ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void showTip(final String str) {
|
private void showTip(final String str) {
|
||||||
mToast.setText(str);
|
if (mToast != null) {
|
||||||
|
mToast.cancel();
|
||||||
|
}
|
||||||
|
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,22 +347,20 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
public void setParam() {
|
public void setParam() {
|
||||||
// 清空参数
|
// 清空参数
|
||||||
mIat.setParameter(SpeechConstant.PARAMS, null);
|
mIat.setParameter(SpeechConstant.PARAMS, null);
|
||||||
|
|
||||||
// 设置听写引擎
|
// 设置听写引擎
|
||||||
mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
|
mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
|
||||||
// 设置返回结果格式
|
// 设置返回结果格式
|
||||||
mIat.setParameter(SpeechConstant.RESULT_TYPE, resultType);
|
mIat.setParameter(SpeechConstant.RESULT_TYPE, resultType);
|
||||||
|
|
||||||
|
|
||||||
if (language.equals("zh_cn")) {
|
if (language.equals("zh_cn")) {
|
||||||
String lag = mSharedPreferences.getString("iat_language_preference",
|
String lag = mSharedPreferences.getString("iat_language_preference",
|
||||||
"mandarin");
|
"mandarin");
|
||||||
Log.e(TAG,"language:"+language);// 设置语言
|
// 设置语言
|
||||||
|
Log.e(TAG, "language = " + language);
|
||||||
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
|
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
|
||||||
// 设置语言区域
|
// 设置语言区域
|
||||||
mIat.setParameter(SpeechConstant.ACCENT, lag);
|
mIat.setParameter(SpeechConstant.ACCENT, lag);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
mIat.setParameter(SpeechConstant.LANGUAGE, language);
|
mIat.setParameter(SpeechConstant.LANGUAGE, language);
|
||||||
}
|
}
|
||||||
Log.e(TAG, "last language:" + mIat.getParameter(SpeechConstant.LANGUAGE));
|
Log.e(TAG, "last language:" + mIat.getParameter(SpeechConstant.LANGUAGE));
|
||||||
@ -446,39 +377,15 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
|
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
|
||||||
mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1"));
|
mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1"));
|
||||||
|
|
||||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
// 设置音频保存路径,保存音频格式支持pcm、wav.
|
||||||
mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
||||||
mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/iat.wav");
|
mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH,
|
||||||
|
getExternalFilesDir("msc").getAbsolutePath() + "/iat.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
@Override
|
* 执行音频流识别操作
|
||||||
protected void onDestroy() {
|
*/
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if( null != mIat ){
|
|
||||||
// 退出时释放连接
|
|
||||||
mIat.cancel();
|
|
||||||
mIat.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
// 开放统计 移动数据统计分析
|
|
||||||
/*FlowerCollector.onResume(IatDemo.this);
|
|
||||||
FlowerCollector.onPageStart(TAG);*/
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
// 开放统计 移动数据统计分析
|
|
||||||
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
//执行音频流识别操作
|
|
||||||
private void executeStream() {
|
private void executeStream() {
|
||||||
buffer.setLength(0);
|
buffer.setLength(0);
|
||||||
mResultText.setText(null);// 清空显示内容
|
mResultText.setText(null);// 清空显示内容
|
||||||
@ -493,32 +400,29 @@ public class IatDemo extends Activity implements OnClickListener {
|
|||||||
ret = mIat.startListening(mRecognizerListener);
|
ret = mIat.startListening(mRecognizerListener);
|
||||||
if (ret != ErrorCode.SUCCESS) {
|
if (ret != ErrorCode.SUCCESS) {
|
||||||
showTip("识别失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
showTip("识别失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||||
} else {
|
return;
|
||||||
byte[] audioData = FucUtil.readAudioFile(IatDemo.this, "iattest.wav");
|
|
||||||
|
|
||||||
if (null != audioData) {
|
|
||||||
showTip(getString(R.string.text_begin_recognizer));
|
|
||||||
// 一次(也可以分多次)写入音频文件数据,数据格式必须是采样率为8KHz或16KHz(本地识别只支持16K采样率,云端都支持),
|
|
||||||
// 位长16bit,单声道的wav或者pcm
|
|
||||||
// 写入8KHz采样的音频时,必须先调用setParameter(SpeechConstant.SAMPLE_RATE, "8000")设置正确的采样率
|
|
||||||
// 注:当音频过长,静音部分时长超过VAD_EOS将导致静音后面部分不能识别。
|
|
||||||
ArrayList<byte[]> bytes = FucUtil.splitBuffer(audioData,audioData.length,audioData.length/3);
|
|
||||||
for(int i=0;i<bytes.size();i++) {
|
|
||||||
mIat.writeAudio(bytes.get(i), 0, bytes.get(i).length );
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}catch(Exception e){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
InputStream open = getAssets().open("iattest.wav");
|
||||||
|
byte[] buff = new byte[1280];
|
||||||
|
while (open.available() > 0) {
|
||||||
|
int read = open.read(buff);
|
||||||
|
mIat.writeAudio(buff, 0, read);
|
||||||
}
|
}
|
||||||
mIat.stopListening();
|
mIat.stopListening();
|
||||||
/*mIat.writeAudio(audioData, 0, audioData.length );
|
} catch (IOException e) {
|
||||||
mIat.stopListening();*/
|
|
||||||
} else {
|
|
||||||
mIat.cancel();
|
mIat.cancel();
|
||||||
showTip("读取音频流失败");
|
showTip("读取音频流失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (mIat != null) {
|
||||||
|
// 退出时释放连接
|
||||||
|
mIat.cancel();
|
||||||
|
mIat.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import android.media.ExifInterface;
|
|||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
@ -32,9 +31,7 @@ import com.iflytek.cloud.IdentityVerifier;
|
|||||||
import com.iflytek.cloud.InitListener;
|
import com.iflytek.cloud.InitListener;
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
import com.iflytek.cloud.SpeechError;
|
import com.iflytek.cloud.SpeechError;
|
||||||
import com.iflytek.speech.util.FaceUtil;
|
|
||||||
import com.iflytek.voicedemo.R;
|
import com.iflytek.voicedemo.R;
|
||||||
import com.iflytek.voicedemo.faceonline.OnlineFaceDemo;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -51,7 +48,7 @@ import java.io.IOException;
|
|||||||
* @author hjyu
|
* @author hjyu
|
||||||
* @date 2017/9/28.
|
* @date 2017/9/28.
|
||||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||||
* */
|
*/
|
||||||
public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
||||||
private final static String TAG = FaceIdentifyActivity.class.getSimpleName();
|
private final static String TAG = FaceIdentifyActivity.class.getSimpleName();
|
||||||
|
|
||||||
@ -171,7 +168,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
case R.id.online_camera:
|
case R.id.online_camera:
|
||||||
// 设置相机拍照后照片保存路径
|
// 设置相机拍照后照片保存路径
|
||||||
mPictureFile = new File(Environment.getExternalStorageDirectory(),
|
mPictureFile = new File(getExternalFilesDir("msc").getAbsolutePath(),
|
||||||
"picture" + System.currentTimeMillis() / 1000 + ".jpg");
|
"picture" + System.currentTimeMillis() / 1000 + ".jpg");
|
||||||
// 启动拍照,并保存到临时文件
|
// 启动拍照,并保存到临时文件
|
||||||
Intent mIntent = new Intent();
|
Intent mIntent = new Intent();
|
||||||
@ -218,15 +215,13 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
|||||||
try {
|
try {
|
||||||
String resultStr = result.getResultString();
|
String resultStr = result.getResultString();
|
||||||
JSONObject resultJson = new JSONObject(resultStr);
|
JSONObject resultJson = new JSONObject(resultStr);
|
||||||
if(ErrorCode.SUCCESS == resultJson.getInt("ret"))
|
if (ErrorCode.SUCCESS == resultJson.getInt("ret")) {
|
||||||
{
|
|
||||||
// 跳转到结果展示页面
|
// 跳转到结果展示页面
|
||||||
Intent intent = new Intent(FaceIdentifyActivity.this, ResultIdentifyActivity.class);
|
Intent intent = new Intent(FaceIdentifyActivity.this, ResultIdentifyActivity.class);
|
||||||
intent.putExtra("result", resultStr);
|
intent.putExtra("result", resultStr);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
this.finish();
|
this.finish();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
showTip("鉴别失败!");
|
showTip("鉴别失败!");
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -394,6 +389,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toast弹出提示
|
* Toast弹出提示
|
||||||
|
*
|
||||||
* @param str
|
* @param str
|
||||||
*/
|
*/
|
||||||
private void showTip(final String str) {
|
private void showTip(final String str) {
|
||||||
@ -426,24 +422,22 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置保存图片路径
|
* 设置保存图片路径
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getImagePath() {
|
private String getImagePath() {
|
||||||
String path;
|
String path = getExternalFilesDir("msc_face").getAbsolutePath() + "/MFVDemo";
|
||||||
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/MFVDemo/";
|
|
||||||
File folder = new File(path);
|
File folder = new File(path);
|
||||||
if (folder != null && !folder.exists()) {
|
if (!folder.exists()) {
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
path += "mfvtest.jpg";
|
path += "/mfvtest.jpg";
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存Bitmap至本地
|
* 保存Bitmap至本地
|
||||||
|
*
|
||||||
* @param bmp
|
* @param bmp
|
||||||
*/
|
*/
|
||||||
private void saveBitmapToFile(Bitmap bmp) {
|
private void saveBitmapToFile(Bitmap bmp) {
|
||||||
|
@ -41,13 +41,13 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* 声纹密码和人脸识别相关组操作
|
* 声纹密码和人脸识别相关组操作
|
||||||
* 支持组创建/添加成员/查询组成员/删除成员/删除组/
|
* 支持组创建/添加成员/查询组成员/删除成员/删除组/
|
||||||
|
*
|
||||||
|
* @author hjyu
|
||||||
|
* @date 2017/9/28.
|
||||||
* @see this#createGroup()
|
* @see this#createGroup()
|
||||||
* @see this#joinGroup(String)
|
* @see this#joinGroup(String)
|
||||||
* @see //this#queryGroups()
|
* @see //this#queryGroups()
|
||||||
* @see this#deleteGroup(String, boolean) ,第二个参数用于标示删除组成员or组
|
* @see this#deleteGroup(String, boolean) ,第二个参数用于标示删除组成员or组
|
||||||
*
|
|
||||||
* @author hjyu
|
|
||||||
* @date 2017/9/28.
|
|
||||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||||
*/
|
*/
|
||||||
public class GroupManagerActivity extends Activity implements OnClickListener, AdapterView.OnItemClickListener {
|
public class GroupManagerActivity extends Activity implements OnClickListener, AdapterView.OnItemClickListener {
|
||||||
@ -171,11 +171,7 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
|
|||||||
Map<String, String> map = (Map<String, String>) parent.getAdapter().getItem(position);
|
Map<String, String> map = (Map<String, String>) parent.getAdapter().getItem(position);
|
||||||
|
|
||||||
init.putExtra("group_id", map.get("group_id"));
|
init.putExtra("group_id", map.get("group_id"));
|
||||||
if (mfv_type.equals("ivp")) {
|
|
||||||
init.setClass(GroupManagerActivity.this,VocalIdentifyActivity.class);
|
|
||||||
}else {
|
|
||||||
init.setClass(GroupManagerActivity.this, FaceIdentifyActivity.class);
|
init.setClass(GroupManagerActivity.this, FaceIdentifyActivity.class);
|
||||||
}
|
|
||||||
startActivity(init);
|
startActivity(init);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,10 +417,12 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
|
|||||||
showTip("查询成功");
|
showTip("查询成功");
|
||||||
stopProgress();
|
stopProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(SpeechError error) {
|
public void onError(SpeechError error) {
|
||||||
Log.d(TAG, error.getPlainDescription(true));
|
Log.d(TAG, error.getPlainDescription(true));
|
||||||
|
@ -22,6 +22,7 @@ import java.text.DecimalFormat;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 1:N检测结果解析界面
|
* 1:N检测结果解析界面
|
||||||
|
*
|
||||||
* @author hjyu
|
* @author hjyu
|
||||||
* @date 2017/9/28.
|
* @date 2017/9/28.
|
||||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||||
|
@ -1,31 +1,30 @@
|
|||||||
package com.iflytek.voicedemo;
|
package com.iflytek.voicedemo;
|
||||||
|
|
||||||
import com.iflytek.cloud.ErrorCode;
|
|
||||||
import com.iflytek.ise.result.Result;
|
|
||||||
import com.iflytek.ise.result.xml.XmlResultParser;
|
|
||||||
import com.iflytek.speech.setting.IseSettings;
|
|
||||||
import com.iflytek.speech.util.FucUtil;
|
|
||||||
/*import com.iflytek.sunflower.FlowerCollector;*/
|
|
||||||
import com.iflytek.cloud.EvaluatorListener;
|
|
||||||
import com.iflytek.cloud.EvaluatorResult;
|
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
|
||||||
import com.iflytek.cloud.SpeechError;
|
|
||||||
import com.iflytek.cloud.SpeechEvaluator;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.iflytek.cloud.EvaluatorListener;
|
||||||
|
import com.iflytek.cloud.EvaluatorResult;
|
||||||
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
|
import com.iflytek.cloud.SpeechError;
|
||||||
|
import com.iflytek.cloud.SpeechEvaluator;
|
||||||
|
import com.iflytek.ise.result.Result;
|
||||||
|
import com.iflytek.ise.result.xml.XmlResultParser;
|
||||||
|
import com.iflytek.speech.setting.IseSettings;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音评测demo
|
* 语音评测demo
|
||||||
*/
|
*/
|
||||||
@ -36,7 +35,7 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
private final static int REQUEST_CODE_SETTINGS = 1;
|
private final static int REQUEST_CODE_SETTINGS = 1;
|
||||||
|
|
||||||
private EditText mEvaTextEditText;
|
private EditText mEvaTextEditText;
|
||||||
private EditText mResultEditText;
|
private TextView mResultEditText;
|
||||||
private Button mIseStartButton;
|
private Button mIseStartButton;
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
|
|
||||||
@ -127,7 +126,7 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
private void initUI() {
|
private void initUI() {
|
||||||
findViewById(R.id.image_ise_set).setOnClickListener(IseDemo.this);
|
findViewById(R.id.image_ise_set).setOnClickListener(IseDemo.this);
|
||||||
mEvaTextEditText = (EditText) findViewById(R.id.ise_eva_text);
|
mEvaTextEditText = (EditText) findViewById(R.id.ise_eva_text);
|
||||||
mResultEditText = (EditText)findViewById(R.id.ise_result_text);
|
mResultEditText = (TextView) findViewById(R.id.ise_result_text);
|
||||||
mIseStartButton = (Button) findViewById(R.id.ise_start);
|
mIseStartButton = (Button) findViewById(R.id.ise_start);
|
||||||
mIseStartButton.setOnClickListener(IseDemo.this);
|
mIseStartButton.setOnClickListener(IseDemo.this);
|
||||||
findViewById(R.id.ise_parse).setOnClickListener(IseDemo.this);
|
findViewById(R.id.ise_parse).setOnClickListener(IseDemo.this);
|
||||||
@ -186,6 +185,16 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
case R.id.ise_parse:
|
case R.id.ise_parse:
|
||||||
// 解析最终结果
|
// 解析最终结果
|
||||||
if (!TextUtils.isEmpty(mLastResult)) {
|
if (!TextUtils.isEmpty(mLastResult)) {
|
||||||
|
// 拦截不支持的解析类型
|
||||||
|
if ("complete".equals(result_level)) {
|
||||||
|
if ("simple_expression".equals(category) || "read_choice".equals(category)
|
||||||
|
|| "topic".equals(category) || "retell".equals(category)
|
||||||
|
|| "picture_talk".equals(category) || "oral_translation".equals(category)) {
|
||||||
|
showTip("不支持解析该类型");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XmlResultParser resultParser = new XmlResultParser();
|
XmlResultParser resultParser = new XmlResultParser();
|
||||||
Result result = resultParser.parse(mLastResult);
|
Result result = resultParser.parse(mLastResult);
|
||||||
|
|
||||||
@ -240,19 +249,51 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
String text = "";
|
String text = "";
|
||||||
if ("en_us".equals(language)) {
|
if ("en_us".equals(language)) {
|
||||||
if ("read_word".equals(category)) {
|
switch (category) {
|
||||||
|
case "read_word": // 词语
|
||||||
text = getString(R.string.text_en_word);
|
text = getString(R.string.text_en_word);
|
||||||
} else if ("read_sentence".equals(category)) {
|
break;
|
||||||
|
case "read_sentence": // 句子
|
||||||
text = getString(R.string.text_en_sentence);
|
text = getString(R.string.text_en_sentence);
|
||||||
|
break;
|
||||||
|
case "read_chapter": // 篇章
|
||||||
|
text = getString(R.string.text_en_chapter);
|
||||||
|
break;
|
||||||
|
case "simple_expression": // 英文情景反应
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_simple_expression), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
|
case "read_choice": // 英文选择题
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_read_choice), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
|
case "topic": // 英文自由题
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_topic), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
|
case "retell": // 英文复述题
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_retell), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
|
case "picture_talk": // 英文看图说话
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_picture_talk), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
|
case "oral_translation": // 英文口头翻译
|
||||||
|
text = new String(Base64.decode(getString(R.string.text_en_oral_translation), Base64.DEFAULT));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 中文评测
|
// 中文评测
|
||||||
if ("read_syllable".equals(category)) {
|
switch (category) {
|
||||||
|
case "read_syllable":
|
||||||
text = getString(R.string.text_cn_syllable);
|
text = getString(R.string.text_cn_syllable);
|
||||||
} else if ("read_word".equals(category)) {
|
break;
|
||||||
|
case "read_word":
|
||||||
text = getString(R.string.text_cn_word);
|
text = getString(R.string.text_cn_word);
|
||||||
} else if ("read_sentence".equals(category)) {
|
break;
|
||||||
|
case "read_sentence":
|
||||||
text = getString(R.string.text_cn_sentence);
|
text = getString(R.string.text_cn_sentence);
|
||||||
|
break;
|
||||||
|
case "read_chapter":
|
||||||
|
text = getString(R.string.text_cn_chapter);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,11 +305,14 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
private void showTip(String str) {
|
private void showTip(String str) {
|
||||||
if (!TextUtils.isEmpty(str)) {
|
if (!TextUtils.isEmpty(str)) {
|
||||||
|
mToast.cancel();
|
||||||
mToast.setText(str);
|
mToast.setText(str);
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setParams() {
|
private void setParams() {
|
||||||
|
|
||||||
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
||||||
// 设置评测语言
|
// 设置评测语言
|
||||||
language = pref.getString(SpeechConstant.LANGUAGE, "zh_cn");
|
language = pref.getString(SpeechConstant.LANGUAGE, "zh_cn");
|
||||||
@ -283,6 +327,21 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
// 语音输入超时时间,即用户最多可以连续说多长时间;
|
// 语音输入超时时间,即用户最多可以连续说多长时间;
|
||||||
String speech_timeout = pref.getString(SpeechConstant.KEY_SPEECH_TIMEOUT, "-1");
|
String speech_timeout = pref.getString(SpeechConstant.KEY_SPEECH_TIMEOUT, "-1");
|
||||||
|
|
||||||
|
// 设置流式版本所需参数 : ent sub plev
|
||||||
|
if ("zh_cn".equals(language)) {
|
||||||
|
mIse.setParameter("ent", "cn_vip");
|
||||||
|
}
|
||||||
|
if ("en_us".equals(language)) {
|
||||||
|
mIse.setParameter("ent", "en_vip");
|
||||||
|
}
|
||||||
|
mIse.setParameter(SpeechConstant.SUBJECT, "ise");
|
||||||
|
mIse.setParameter("plev", "0");
|
||||||
|
|
||||||
|
// 设置评分百分制 使用 ise_unite rst extra_ability 参数
|
||||||
|
mIse.setParameter("ise_unite", "1");
|
||||||
|
mIse.setParameter("rst", "entirety");
|
||||||
|
mIse.setParameter("extra_ability", "syll_phone_err_msg;pitch;multi_dimension");
|
||||||
|
|
||||||
mIse.setParameter(SpeechConstant.LANGUAGE, language);
|
mIse.setParameter(SpeechConstant.LANGUAGE, language);
|
||||||
mIse.setParameter(SpeechConstant.ISE_CATEGORY, category);
|
mIse.setParameter(SpeechConstant.ISE_CATEGORY, category);
|
||||||
mIse.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
mIse.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
||||||
@ -291,26 +350,12 @@ public class IseDemo extends Activity implements OnClickListener {
|
|||||||
mIse.setParameter(SpeechConstant.KEY_SPEECH_TIMEOUT, speech_timeout);
|
mIse.setParameter(SpeechConstant.KEY_SPEECH_TIMEOUT, speech_timeout);
|
||||||
mIse.setParameter(SpeechConstant.RESULT_LEVEL, result_level);
|
mIse.setParameter(SpeechConstant.RESULT_LEVEL, result_level);
|
||||||
mIse.setParameter(SpeechConstant.AUDIO_FORMAT_AUE, "opus");
|
mIse.setParameter(SpeechConstant.AUDIO_FORMAT_AUE, "opus");
|
||||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
// 设置音频保存路径,保存音频格式支持pcm、wav,
|
||||||
mIse.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
mIse.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
||||||
mIse.setParameter(SpeechConstant.ISE_AUDIO_PATH, Environment.getExternalStorageDirectory().getAbsolutePath() + "/msc/ise.wav");
|
mIse.setParameter(SpeechConstant.ISE_AUDIO_PATH,
|
||||||
|
getExternalFilesDir("msc").getAbsolutePath() + "/ise.wav");
|
||||||
//通过writeaudio方式直接写入音频时才需要此设置
|
//通过writeaudio方式直接写入音频时才需要此设置
|
||||||
//mIse.setParameter(SpeechConstant.AUDIO_SOURCE,"-1");
|
//mIse.setParameter(SpeechConstant.AUDIO_SOURCE,"-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
// 开放统计 移动数据统计分析
|
|
||||||
/*FlowerCollector.onResume(IseDemo.this);
|
|
||||||
FlowerCollector.onPageStart(TAG);*/
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
/* // 开放统计 移动数据统计分析
|
|
||||||
FlowerCollector.onPageEnd(TAG);
|
|
||||||
FlowerCollector.onPause(IseDemo.this);*/
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,189 +1,75 @@
|
|||||||
package com.iflytek.voicedemo;
|
package com.iflytek.voicedemo;
|
||||||
|
|
||||||
import com.iflytek.cloud.SpeechUtility;
|
|
||||||
import com.iflytek.speech.setting.UrlSettings;
|
|
||||||
|
|
||||||
import com.iflytek.voicedemo.faceonline.OnlineFaceDemo;
|
|
||||||
import com.iflytek.voicedemo.vocalverify.VocalVerifyDemo;
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import static com.iflytek.speech.setting.UrlSettings.PREFER_NAME;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
public class MainActivity extends Activity implements OnClickListener {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
private static final String TAG = MainActivity.class.getSimpleName();
|
|
||||||
private Toast mToast;
|
|
||||||
private final int URL_REQUEST_CODE = 0X001;
|
|
||||||
private TextView edit_text;
|
|
||||||
|
|
||||||
@SuppressLint("ShowToast")
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
edit_text = (TextView) findViewById(R.id.edit_text);
|
initView();
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
buf.append("当前APPID为:");
|
|
||||||
buf.append(getString(R.string.app_id)+"\n");
|
|
||||||
buf.append(getString(R.string.example_explain));
|
|
||||||
edit_text.setText(buf);
|
|
||||||
requestPermissions();
|
requestPermissions();
|
||||||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
|
|
||||||
//mscInit(null);//采用sdk默认url
|
|
||||||
SimpleAdapter listitemAdapter = new SimpleAdapter();
|
|
||||||
((ListView) findViewById(R.id.listview_main)).setAdapter(listitemAdapter);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initView() {
|
||||||
public void onClick(View view) {
|
TextView tipTv = (TextView) findViewById(R.id.tip);
|
||||||
int tag = Integer.parseInt(view.getTag().toString());
|
String buf = "当前APPID为:" +
|
||||||
Intent intent = null;
|
getString(R.string.app_id) + "\n" +
|
||||||
switch (tag) {
|
getString(R.string.example_explain);
|
||||||
case 0:
|
tipTv.setText(buf);
|
||||||
// 语音转写
|
// 语音转写
|
||||||
intent = new Intent(MainActivity.this, IatDemo.class);
|
findViewById(R.id.iatBtn).setOnClickListener(v -> {
|
||||||
break;
|
startActivity(new Intent(MainActivity.this, IatDemo.class));
|
||||||
case 1:
|
});
|
||||||
// 语法识别
|
// 语法识别
|
||||||
intent = new Intent(MainActivity.this, AsrDemo.class);
|
findViewById(R.id.asrBtn).setOnClickListener(v -> {
|
||||||
break;
|
startActivity(new Intent(MainActivity.this, AsrDemo.class));
|
||||||
case 2:
|
});
|
||||||
// 语义理解
|
// 语义理解
|
||||||
|
findViewById(R.id.nlpBtn).setOnClickListener(v -> {
|
||||||
showTip("请登录:http://www.xfyun.cn/ 下载aiui体验吧!");
|
showTip("请登录:http://www.xfyun.cn/ 下载aiui体验吧!");
|
||||||
break;
|
});
|
||||||
case 3:
|
|
||||||
// 语音合成
|
// 语音合成
|
||||||
intent = new Intent(MainActivity.this, TtsDemo.class);
|
findViewById(R.id.ttsBtn).setOnClickListener(v -> {
|
||||||
break;
|
startActivity(new Intent(MainActivity.this, TtsDemo.class));
|
||||||
case 4:
|
});
|
||||||
// 语音评测
|
// 语音评测
|
||||||
intent = new Intent(MainActivity.this, IseDemo.class);
|
findViewById(R.id.iseBtn).setOnClickListener(v -> {
|
||||||
break;
|
startActivity(new Intent(MainActivity.this, IseDemo.class));
|
||||||
case 5:
|
});
|
||||||
// 唤醒
|
// 人脸识别
|
||||||
showTip("请登录:http://www.xfyun.cn/ 下载体验吧!");
|
findViewById(R.id.faceBtn).setOnClickListener(v -> {
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
// 声纹
|
|
||||||
//intent = new Intent(MainActivity.this, VocalVerifyDemo.class);
|
|
||||||
showTip("请登录:http://www.xfyun.cn/ “声纹识别”下载体验吧!");
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
//intent = new Intent(MainActivity.this,OnlineFaceDemo.class);
|
|
||||||
showTip("请登录:http://www.xfyun.cn/ “人脸识别”下载体验吧!");
|
showTip("请登录:http://www.xfyun.cn/ “人脸识别”下载体验吧!");
|
||||||
break;
|
});
|
||||||
/*case 8:
|
|
||||||
Intent init = new Intent(MainActivity.this, UrlSettings.class);
|
|
||||||
startActivityForResult(init, URL_REQUEST_CODE);
|
|
||||||
break;*/
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent != null) {
|
private Toast mToast;
|
||||||
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) {
|
private void showTip(final String str) {
|
||||||
mToast.setText(str);
|
if (mToast != null) {
|
||||||
|
mToast.cancel();
|
||||||
|
}
|
||||||
|
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
// 开放统计 移动数据统计分析
|
|
||||||
/*FlowerCollector.onResume(MainActivity.this);
|
|
||||||
FlowerCollector.onPageStart(TAG);*/
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
// 开放统计 移动数据统计分析
|
|
||||||
/* FlowerCollector.onPageEnd(TAG);
|
|
||||||
FlowerCollector.onPause(MainActivity.this);*/
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requestPermissions() {
|
private void requestPermissions() {
|
||||||
try {
|
try {
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(permission != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
ActivityCompat.requestPermissions(this, new String[]{
|
ActivityCompat.requestPermissions(this, new String[]{
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
Manifest.permission.RECORD_AUDIO,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION},0x0010);
|
Manifest.permission.CAMERA
|
||||||
}
|
}, 0x0010);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -195,58 +81,4 @@ public class MainActivity extends Activity implements OnClickListener {
|
|||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mscInit (String serverUrl){
|
|
||||||
// 注意:此接口在非主进程调用会返回null对象,如需在非主进程使用语音功能,请增加参数:SpeechConstant.FORCE_LOGIN+"=true"
|
|
||||||
// 参数间使用半角“,”分隔。
|
|
||||||
// 设置你申请的应用appid,请勿在'='与appid之间添加空格及空转义符
|
|
||||||
|
|
||||||
// 注意: appid 必须和下载的SDK保持一致,否则会出现10407错误
|
|
||||||
StringBuffer bf = new StringBuffer();
|
|
||||||
bf.append("appid="+getString(R.string.app_id));
|
|
||||||
bf.append(",");
|
|
||||||
if (!TextUtils.isEmpty(serverUrl)) {
|
|
||||||
bf.append("server_url="+serverUrl);
|
|
||||||
bf.append(",");
|
|
||||||
}
|
|
||||||
//此处调用与SpeechDemo中重复,两处只调用其一即可
|
|
||||||
SpeechUtility.createUtility(this.getApplicationContext(), bf.toString());
|
|
||||||
// 以下语句用于设置日志开关(默认开启),设置成false时关闭语音云SDK日志打印
|
|
||||||
// Setting.setShowLog(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mscUninit() {
|
|
||||||
if (SpeechUtility.getUtility()!= null) {
|
|
||||||
SpeechUtility.getUtility().destroy();
|
|
||||||
try{
|
|
||||||
new Thread().sleep(40);
|
|
||||||
}catch (InterruptedException e) {
|
|
||||||
Log.w(TAG,"msc uninit failed"+e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
if (URL_REQUEST_CODE == requestCode) {
|
|
||||||
Log.d(TAG,"onActivityResult>>");
|
|
||||||
try{
|
|
||||||
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
|
||||||
String server_url = pref.getString("url_preference","");
|
|
||||||
String domain = pref.getString("url_edit","");
|
|
||||||
Log.d(TAG,"onActivityResult>>domain = "+domain);
|
|
||||||
if (!TextUtils.isEmpty(domain)) {
|
|
||||||
server_url = "http://"+domain+"/msp.do";
|
|
||||||
}
|
|
||||||
Log.d(TAG,"onActivityResult>>server_url = "+server_url);
|
|
||||||
mscUninit();
|
|
||||||
new Thread().sleep(40);
|
|
||||||
//mscInit(server_url);
|
|
||||||
}catch (Exception e) {
|
|
||||||
showTip("reset url failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.iflytek.voicedemo;
|
package com.iflytek.voicedemo;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import com.iflytek.cloud.Setting;
|
import com.iflytek.cloud.Setting;
|
||||||
import com.iflytek.cloud.SpeechUtility;
|
import com.iflytek.cloud.SpeechUtility;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ public class SpeechApp extends Application {
|
|||||||
SpeechUtility.createUtility(SpeechApp.this, "appid=" + getString(R.string.app_id));
|
SpeechUtility.createUtility(SpeechApp.this, "appid=" + getString(R.string.app_id));
|
||||||
|
|
||||||
// 以下语句用于设置日志开关(默认开启),设置成false时关闭语音云SDK日志打印
|
// 以下语句用于设置日志开关(默认开启),设置成false时关闭语音云SDK日志打印
|
||||||
// Setting.setShowLog(false);
|
Setting.setShowLog(true);
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.iflytek.voicedemo;
|
package com.iflytek.voicedemo;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -8,8 +7,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.MemoryFile;
|
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.style.BackgroundColorSpan;
|
import android.text.style.BackgroundColorSpan;
|
||||||
@ -29,15 +26,11 @@ import com.iflytek.cloud.SpeechError;
|
|||||||
import com.iflytek.cloud.SpeechEvent;
|
import com.iflytek.cloud.SpeechEvent;
|
||||||
import com.iflytek.cloud.SpeechSynthesizer;
|
import com.iflytek.cloud.SpeechSynthesizer;
|
||||||
import com.iflytek.cloud.SynthesizerListener;
|
import com.iflytek.cloud.SynthesizerListener;
|
||||||
import com.iflytek.cloud.msc.util.FileUtil;
|
|
||||||
import com.iflytek.cloud.msc.util.log.DebugLog;
|
|
||||||
import com.iflytek.speech.setting.TtsSettings;
|
import com.iflytek.speech.setting.TtsSettings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.RandomAccessFile;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
|
|
||||||
public class TtsDemo extends Activity implements OnClickListener {
|
public class TtsDemo extends Activity implements OnClickListener {
|
||||||
@ -50,7 +43,7 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
private String[] mCloudVoicersEntries;
|
private String[] mCloudVoicersEntries;
|
||||||
private String[] mCloudVoicersValue;
|
private String[] mCloudVoicersValue;
|
||||||
String texts = "";
|
private String texts = "";
|
||||||
|
|
||||||
// 缓冲进度
|
// 缓冲进度
|
||||||
private int mPercentForBuffering = 0;
|
private int mPercentForBuffering = 0;
|
||||||
@ -64,30 +57,20 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
private SharedPreferences mSharedPreferences;
|
private SharedPreferences mSharedPreferences;
|
||||||
|
private File pcmFile;
|
||||||
|
|
||||||
MemoryFile memFile;
|
|
||||||
public volatile long mTotalSize = 0;
|
|
||||||
|
|
||||||
private Vector<byte[]> container = new Vector<> ();
|
|
||||||
|
|
||||||
@SuppressLint("ShowToast")
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(R.layout.ttsdemo);
|
setContentView(R.layout.ttsdemo);
|
||||||
texts = getResources().getString(R.string.text_tts_source);
|
texts = getResources().getString(R.string.text_tts_source);
|
||||||
initLayout();
|
initLayout();
|
||||||
DebugLog.setShowLog(true);
|
|
||||||
// 初始化合成对象
|
// 初始化合成对象
|
||||||
mTts = SpeechSynthesizer.createSynthesizer(TtsDemo.this, mTtsInitListener);
|
mTts = SpeechSynthesizer.createSynthesizer(TtsDemo.this, mTtsInitListener);
|
||||||
|
|
||||||
// 云端发音人名称列表
|
// 云端发音人名称列表
|
||||||
mCloudVoicersEntries = getResources().getStringArray(R.array.voicer_cloud_entries);
|
mCloudVoicersEntries = getResources().getStringArray(R.array.voicer_cloud_entries);
|
||||||
mCloudVoicersValue = getResources().getStringArray(R.array.voicer_cloud_values);
|
mCloudVoicersValue = getResources().getStringArray(R.array.voicer_cloud_values);
|
||||||
|
|
||||||
mSharedPreferences = getSharedPreferences(TtsSettings.PREFER_NAME, MODE_PRIVATE);
|
mSharedPreferences = getSharedPreferences(TtsSettings.PREFER_NAME, MODE_PRIVATE);
|
||||||
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,18 +122,19 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
// 收到onCompleted 回调时,合成结束、生成合成音频
|
// 收到onCompleted 回调时,合成结束、生成合成音频
|
||||||
// 合成的音频格式:只支持pcm格式
|
// 合成的音频格式:只支持pcm格式
|
||||||
case R.id.tts_play:
|
case R.id.tts_play:
|
||||||
// 移动数据分析,收集开始合成事件
|
pcmFile = new File(getExternalCacheDir().getAbsolutePath(), "tts_pcmFile.pcm");
|
||||||
/*FlowerCollector.onEvent(TtsDemo.this, "tts_play");*/
|
pcmFile.delete();
|
||||||
|
|
||||||
texts = ((EditText) findViewById(R.id.tts_text)).getText().toString();
|
texts = ((EditText) findViewById(R.id.tts_text)).getText().toString();
|
||||||
// 设置参数
|
// 设置参数
|
||||||
setParam();
|
setParam();
|
||||||
|
// 合成并播放
|
||||||
int code = mTts.startSpeaking(texts, mTtsListener);
|
int code = mTts.startSpeaking(texts, mTtsListener);
|
||||||
// /**
|
// /**
|
||||||
// * 只保存音频不进行播放接口,调用此接口请注释startSpeaking接口
|
// * 只保存音频不进行播放接口,调用此接口请注释startSpeaking接口
|
||||||
// * text:要合成的文本,uri:需要保存的音频全路径,listener:回调接口
|
// * text:要合成的文本,uri:需要保存的音频全路径,listener:回调接口
|
||||||
// */
|
// */
|
||||||
String path = Environment.getExternalStorageDirectory()+"/tts.pcm";
|
// String path = getExternalFilesDir("msc").getAbsolutePath() + "/tts.pcm";
|
||||||
|
// // synthesizeToUri 只保存音频不进行播放
|
||||||
// int code = mTts.synthesizeToUri(texts, path, mTtsListener);
|
// int code = mTts.synthesizeToUri(texts, path, mTtsListener);
|
||||||
|
|
||||||
if (code != ErrorCode.SUCCESS) {
|
if (code != ErrorCode.SUCCESS) {
|
||||||
@ -171,15 +155,17 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
break;
|
break;
|
||||||
// 选择发音人
|
// 选择发音人
|
||||||
case R.id.tts_btn_person_select:
|
case R.id.tts_btn_person_select:
|
||||||
showPresonSelectDialog();
|
showPersonSelectDialog();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int selectedNum = 0;
|
private int selectedNum = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发音人选择。
|
* 发音人选择。
|
||||||
*/
|
*/
|
||||||
private void showPresonSelectDialog() {
|
private void showPersonSelectDialog() {
|
||||||
switch (mRadioGroup.getCheckedRadioButtonId()) {
|
switch (mRadioGroup.getCheckedRadioButtonId()) {
|
||||||
// 选择在线合成
|
// 选择在线合成
|
||||||
case R.id.tts_radioCloud:
|
case R.id.tts_radioCloud:
|
||||||
@ -269,22 +255,10 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted(SpeechError error) {
|
public void onCompleted(SpeechError error) {
|
||||||
System.out.println("oncompleted");
|
showTip("播放完成");
|
||||||
if (error == null) {
|
if (error != null) {
|
||||||
// showTip("播放完成");
|
|
||||||
DebugLog.LogD("播放完成,"+container.size());
|
|
||||||
try {
|
|
||||||
for(int i=0;i<container.size();i++) {
|
|
||||||
writeToFile(container.get(i));
|
|
||||||
}
|
|
||||||
}catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
FileUtil.saveFile(memFile,mTotalSize,Environment.getExternalStorageDirectory()+"/1.pcm");
|
|
||||||
|
|
||||||
|
|
||||||
} else if (error != null) {
|
|
||||||
showTip(error.getPlainDescription(true));
|
showTip(error.getPlainDescription(true));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,24 +270,30 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
||||||
Log.d(TAG, "session id =" + sid);
|
Log.d(TAG, "session id =" + sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当设置 SpeechConstant.TTS_DATA_NOTIFY 为1时,抛出buf数据
|
// 当设置 SpeechConstant.TTS_DATA_NOTIFY 为1时,抛出buf数据
|
||||||
if (SpeechEvent.EVENT_TTS_BUFFER == eventType) {
|
if (SpeechEvent.EVENT_TTS_BUFFER == eventType) {
|
||||||
byte[] buf = obj.getByteArray(SpeechEvent.KEY_EVENT_TTS_BUFFER);
|
byte[] buf = obj.getByteArray(SpeechEvent.KEY_EVENT_TTS_BUFFER);
|
||||||
Log.e("MscSpeechLog_", "bufis =" + buf.length);
|
Log.e(TAG, "EVENT_TTS_BUFFER = " + buf.length);
|
||||||
container.add(buf);
|
// 保存文件
|
||||||
|
appendFile(pcmFile, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void showTip(final String str) {
|
private void showTip(final String str) {
|
||||||
Toast.makeText(this,str,Toast.LENGTH_SHORT);
|
runOnUiThread(() -> {
|
||||||
|
if (mToast != null) {
|
||||||
|
mToast.cancel();
|
||||||
|
}
|
||||||
|
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
|
||||||
|
mToast.show();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数设置
|
* 参数设置
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void setParam() {
|
private void setParam() {
|
||||||
@ -347,49 +327,35 @@ public class TtsDemo extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
||||||
mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "pcm");
|
mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "pcm");
|
||||||
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/tts.pcm");
|
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH,
|
||||||
|
getExternalFilesDir("msc").getAbsolutePath() + "/tts.pcm");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (null != mTts) {
|
if (null != mTts) {
|
||||||
mTts.stopSpeaking();
|
mTts.stopSpeaking();
|
||||||
// 退出时释放连接
|
// 退出时释放连接
|
||||||
mTts.destroy();
|
mTts.destroy();
|
||||||
}
|
}
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
//移动数据统计分析
|
|
||||||
/*FlowerCollector.onResume(TtsDemo.this);
|
|
||||||
FlowerCollector.onPageStart(TAG);*/
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
//移动数据统计分析
|
|
||||||
/*FlowerCollector.onPageEnd(TAG);
|
|
||||||
FlowerCollector.onPause(TtsDemo.this);*/
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeToFile(byte[] data) throws IOException {
|
/**
|
||||||
if (data == null || data.length == 0)
|
* 给file追加数据
|
||||||
return;
|
*/
|
||||||
|
private void appendFile(File file, byte[] buffer) {
|
||||||
try {
|
try {
|
||||||
if(memFile == null)
|
if (!file.exists()) {
|
||||||
{
|
boolean b = file.createNewFile();
|
||||||
Log.e("MscSpeechLog_","ffffffffff");
|
|
||||||
String mFilepath = Environment.getExternalStorageDirectory()+"/1.pcm";
|
|
||||||
memFile = new MemoryFile(mFilepath,1920000);
|
|
||||||
memFile.allowPurging(false);
|
|
||||||
}
|
}
|
||||||
memFile.writeBytes(data, 0, (int)mTotalSize, data.length);
|
RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
|
||||||
mTotalSize += data.length;
|
randomFile.seek(file.length());
|
||||||
} finally {
|
randomFile.write(buffer);
|
||||||
|
randomFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,12 @@ import android.app.Activity;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.SystemClock;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -19,7 +18,6 @@ import android.view.View;
|
|||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.iflytek.cloud.ErrorCode;
|
import com.iflytek.cloud.ErrorCode;
|
||||||
@ -29,11 +27,9 @@ import com.iflytek.cloud.IdentityVerifier;
|
|||||||
import com.iflytek.cloud.InitListener;
|
import com.iflytek.cloud.InitListener;
|
||||||
import com.iflytek.cloud.SpeechConstant;
|
import com.iflytek.cloud.SpeechConstant;
|
||||||
import com.iflytek.cloud.SpeechError;
|
import com.iflytek.cloud.SpeechError;
|
||||||
import com.iflytek.cloud.SpeechUtility;
|
|
||||||
import com.iflytek.speech.util.FaceUtil;
|
import com.iflytek.speech.util.FaceUtil;
|
||||||
import com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity;
|
import com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity;
|
||||||
import com.iflytek.voicedemo.R;
|
import com.iflytek.voicedemo.R;
|
||||||
import com.iflytek.voicedemo.vocalverify.VocalVerifyDemo;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -42,18 +38,14 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* 此demo意在为提供在线人脸识别相关api调用方式,1:1 识别
|
* 此demo意在为提供在线人脸识别相关api调用方式,1:1 识别
|
||||||
*
|
*
|
||||||
* @author hjyu
|
* @author hjyu
|
||||||
* @date 2017/9/28.
|
* @date 2017/9/28.
|
||||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
||||||
private final String TAG = "OnlineFaceDemo";
|
private final String TAG = "OnlineFaceDemo";
|
||||||
private final int REQUEST_PICTURE_CHOOSE = 1;
|
|
||||||
private final int REQUEST_CAMERA_IMAGE = 2;
|
|
||||||
|
|
||||||
private Bitmap mImage = null;
|
private Bitmap mImage = null;
|
||||||
private byte[] mImageData = null;
|
private byte[] mImageData = null;
|
||||||
@ -149,8 +141,6 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 人脸注册监听器
|
* 人脸注册监听器
|
||||||
*/
|
*/
|
||||||
@ -281,7 +271,6 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void executeModelCommand(String cmd) {
|
private void executeModelCommand(String cmd) {
|
||||||
// 设置模型参数,若无可以传空字符传
|
// 设置模型参数,若无可以传空字符传
|
||||||
StringBuffer params = new StringBuffer();
|
StringBuffer params = new StringBuffer();
|
||||||
@ -305,7 +294,7 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
intent.setAction(Intent.ACTION_PICK);
|
intent.setAction(Intent.ACTION_PICK);
|
||||||
startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
|
startActivityForResult(intent, FaceUtil.REQUEST_PICTURE_CHOOSE);
|
||||||
break;
|
break;
|
||||||
case R.id.online_reg:
|
case R.id.online_reg:
|
||||||
if (TextUtils.isEmpty(mAuthid)) {
|
if (TextUtils.isEmpty(mAuthid)) {
|
||||||
@ -376,15 +365,8 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.online_camera:
|
case R.id.online_camera:
|
||||||
// 设置相机拍照后照片保存路径
|
|
||||||
mPictureFile = new File(Environment.getExternalStorageDirectory(),
|
|
||||||
"picture" + System.currentTimeMillis()/1000 + ".jpg");
|
|
||||||
// 启动拍照,并保存到临时文件
|
// 启动拍照,并保存到临时文件
|
||||||
Intent mIntent = new Intent();
|
takePhoto();
|
||||||
mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
||||||
mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPictureFile));
|
|
||||||
mIntent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
|
|
||||||
startActivityForResult(mIntent, REQUEST_CAMERA_IMAGE);
|
|
||||||
break;
|
break;
|
||||||
case R.id.btn_modle_delete:
|
case R.id.btn_modle_delete:
|
||||||
// 人脸模型删除
|
// 人脸模型删除
|
||||||
@ -407,46 +389,45 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void takePhoto() {
|
||||||
|
// 设置相机拍照后照片保存路径
|
||||||
|
mPictureFile = new File(getExternalFilesDir("msc").getAbsolutePath(),
|
||||||
|
"picture_" + SystemClock.uptimeMillis() + ".jpg");
|
||||||
|
if (mPictureFile.exists()) {
|
||||||
|
mPictureFile.delete();
|
||||||
|
}
|
||||||
|
Uri imageUri = FaceUtil.parseUri(getApplication(), mPictureFile);
|
||||||
|
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
|
||||||
|
startActivityForResult(intent, FaceUtil.REQUEST_CAMERA_IMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode != RESULT_OK) {
|
if (resultCode != RESULT_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileSrc = null;
|
String fileSrc = null;
|
||||||
if (requestCode == REQUEST_PICTURE_CHOOSE) {
|
// 选择文件
|
||||||
if ("file".equals(data.getData().getScheme())) {
|
if (requestCode == FaceUtil.REQUEST_PICTURE_CHOOSE) {
|
||||||
// 有些低版本机型返回的Uri模式为file
|
|
||||||
fileSrc = data.getData().getPath();
|
|
||||||
} else {
|
|
||||||
// Uri模型为content
|
|
||||||
String[] proj = {MediaStore.Images.Media.DATA};
|
|
||||||
Cursor cursor = getContentResolver().query(data.getData(), proj,
|
|
||||||
null, null, null);
|
|
||||||
cursor.moveToFirst();
|
|
||||||
int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
|
||||||
fileSrc = cursor.getString(idx);
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
// 跳转到图片裁剪页面
|
// 跳转到图片裁剪页面
|
||||||
FaceUtil.cropPicture(this,Uri.fromFile(new File(fileSrc)));
|
FaceUtil.cropPicture(this, data.getData());
|
||||||
} else if (requestCode == REQUEST_CAMERA_IMAGE) {
|
return;
|
||||||
if (null == mPictureFile) {
|
}
|
||||||
|
// 拍照
|
||||||
|
if (requestCode == FaceUtil.REQUEST_CAMERA_IMAGE) {
|
||||||
|
if (null == mPictureFile || !mPictureFile.exists()) {
|
||||||
showTip("拍照失败,请重试");
|
showTip("拍照失败,请重试");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSrc = mPictureFile.getAbsolutePath();
|
|
||||||
updateGallery(fileSrc);
|
|
||||||
// 跳转到图片裁剪页面
|
// 跳转到图片裁剪页面
|
||||||
FaceUtil.cropPicture(this,Uri.fromFile(new File(fileSrc)));
|
FaceUtil.cropPicture(
|
||||||
} else if (requestCode == FaceUtil.REQUEST_CROP_IMAGE) {
|
OnlineFaceDemo.this,
|
||||||
// 获取返回数据
|
FaceUtil.parseUri(getApplication(), mPictureFile));
|
||||||
Bitmap bmp = data.getParcelableExtra("data");
|
return;
|
||||||
// 若返回数据不为null,保存至本地,防止裁剪时未能正常保存
|
|
||||||
if(null != bmp){
|
|
||||||
FaceUtil.saveBitmapToFile(OnlineFaceDemo.this, bmp);
|
|
||||||
}
|
}
|
||||||
|
// 裁剪
|
||||||
|
if (requestCode == FaceUtil.REQUEST_CROP_IMAGE) {
|
||||||
// 获取图片保存路径
|
// 获取图片保存路径
|
||||||
fileSrc = FaceUtil.getImagePath(OnlineFaceDemo.this);
|
fileSrc = FaceUtil.getImagePath(OnlineFaceDemo.this);
|
||||||
// 获取图片的宽和高
|
// 获取图片的宽和高
|
||||||
@ -461,29 +442,23 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
mImage = BitmapFactory.decodeFile(fileSrc, options);
|
mImage = BitmapFactory.decodeFile(fileSrc, options);
|
||||||
|
|
||||||
|
|
||||||
// 若mImageBitmap为空则图片信息不能正常获取
|
// 若mImageBitmap为空则图片信息不能正常获取
|
||||||
if (null == mImage) {
|
if (null == mImage) {
|
||||||
showTip("图片信息无法正常获取!");
|
showTip("图片信息无法正常获取!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 部分手机会对图片做旋转,这里检测旋转角度
|
// 部分手机会对图片做旋转,这里检测旋转角度
|
||||||
int degree = FaceUtil.readPictureDegree(fileSrc);
|
int degree = FaceUtil.readPictureDegree(fileSrc);
|
||||||
if (degree != 0) {
|
if (degree != 0) {
|
||||||
// 把图片旋转为正的方向
|
// 把图片旋转为正的方向
|
||||||
mImage = FaceUtil.rotateImage(degree, mImage);
|
mImage = FaceUtil.rotateImage(degree, mImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
//可根据流量及网络状况对图片进行压缩
|
//可根据流量及网络状况对图片进行压缩
|
||||||
mImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);
|
mImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);
|
||||||
mImageData = baos.toByteArray();
|
mImageData = baos.toByteArray();
|
||||||
|
|
||||||
((ImageView) findViewById(R.id.online_img)).setImageBitmap(mImage);
|
((ImageView) findViewById(R.id.online_img)).setImageBitmap(mImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -497,7 +472,6 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
|
|||||||
private void updateGallery(String filename) {
|
private void updateGallery(String filename) {
|
||||||
MediaScannerConnection.scanFile(this, new String[]{filename}, null,
|
MediaScannerConnection.scanFile(this, new String[]{filename}, null,
|
||||||
new MediaScannerConnection.OnScanCompletedListener() {
|
new MediaScannerConnection.OnScanCompletedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<selector
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item android:state_pressed="true" android:drawable="@color/list_backgroud_color"></item>
|
<item android:state_pressed="true" android:drawable="@color/list_backgroud_color"></item>
|
||||||
<item android:drawable="@drawable/layout_backgroud"></item>
|
<item android:drawable="@drawable/layout_backgroud"></item>
|
||||||
</selector>
|
</selector>
|
@ -39,8 +39,6 @@
|
|||||||
android:padding="5dp" />
|
android:padding="5dp" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/group_manager_layout"
|
android:id="@+id/group_manager_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -74,8 +74,7 @@
|
|||||||
android:layout_alignLeft="@id/txt_hint"
|
android:layout_alignLeft="@id/txt_hint"
|
||||||
android:fadingEdge="none"
|
android:fadingEdge="none"
|
||||||
android:cacheColorHint="#00000000"
|
android:cacheColorHint="#00000000"
|
||||||
android:listSelector="#00000000" >
|
android:listSelector="#00000000"></ListView>
|
||||||
</ListView>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/group_manager_layout"
|
android:id="@+id/group_manager_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@ -82,8 +81,7 @@
|
|||||||
android:hint="请输入组名用于创建组..."
|
android:hint="请输入组名用于创建组..."
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:textSize="18sp" >
|
android:textSize="18sp"></EditText>
|
||||||
</EditText>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -35,27 +35,27 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:hint="@string/text_show_iat_result"
|
|
||||||
android:gravity="top|left"
|
android:gravity="top|left"
|
||||||
|
android:hint="@string/text_show_iat_result"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="10dp"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/iat_contacts"
|
android:id="@+id/iat_contacts"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:hint="@string/text_show_contacts"
|
|
||||||
android:gravity="top|left"
|
android:gravity="top|left"
|
||||||
|
android:hint="@string/text_show_contacts"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="10dp"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="2dp"
|
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
@ -89,13 +89,12 @@
|
|||||||
android:id="@+id/languageText"
|
android:id="@+id/languageText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="点击设置小语种,当前语种:中文(普通话)"
|
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:textSize="20sp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
/>
|
android:gravity="center_horizontal"
|
||||||
|
android:text="点击设置小语种,当前语种:中文(普通话)"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/iat_recognize_stream"
|
android:id="@+id/iat_recognize_stream"
|
||||||
@ -109,32 +108,16 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="上传联系人、词表,可以使云端识别联系人和词表更加准确,这里上传的内容对语义理解同样有效。"
|
android:text="上传词表,可以使云端识别更加准确,这里上传的内容对语义理解同样有效。"
|
||||||
android:textSize="@dimen/txt_size" />
|
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
|
<Button
|
||||||
android:id="@+id/iat_upload_userwords"
|
android:id="@+id/iat_upload_userwords"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
android:text="上传词表"
|
android:text="上传词表"
|
||||||
android:textSize="17sp" />
|
android:textSize="17sp" />
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_vertical">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/ifly_mnotice_image_container"
|
android:id="@+id/ifly_mnotice_image_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -28,30 +28,42 @@
|
|||||||
android:background="@drawable/main_setting_btn_np" />
|
android:background="@drawable/main_setting_btn_np" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<EditText
|
<ScrollView
|
||||||
android:id="@+id/ise_eva_text"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginBottom="5dp"
|
android:layout_weight="1">
|
||||||
android:gravity="top|left"
|
|
||||||
android:textSize="20sp" />
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
<EditText
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/ise_result_text"
|
android:orientation="vertical">
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="200dp"
|
<EditText
|
||||||
android:layout_marginBottom="5dp"
|
android:id="@+id/ise_eva_text"
|
||||||
android:layout_weight="1"
|
android:layout_width="match_parent"
|
||||||
android:editable="false"
|
android:layout_height="360dp"
|
||||||
android:gravity="top|left"
|
android:layout_marginBottom="5dp"
|
||||||
android:hint="请点击“开始评测”按钮"
|
android:gravity="top|left"
|
||||||
android:textSize="16sp" />
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ise_result_text"
|
||||||
|
android:minHeight="200dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:hint="请点击“开始评测”按钮"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="2dp"
|
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
@ -75,8 +87,8 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="2dp"
|
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:text="讯飞语法示例"
|
android:text="讯飞语法示例"
|
||||||
|
android:textColor="@color/black"
|
||||||
android:textSize="30sp" />
|
android:textSize="30sp" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
@ -93,8 +93,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text=" 声纹注册"
|
android:text=" 声纹注册"
|
||||||
android:textSize="18sp" >
|
android:textSize="18sp"></RadioButton>
|
||||||
</RadioButton>
|
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/vocal_radioVerify"
|
android:id="@+id/vocal_radioVerify"
|
||||||
@ -102,8 +101,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text=" 1:1验证"
|
android:text=" 1:1验证"
|
||||||
android:textSize="18sp" >
|
android:textSize="18sp"></RadioButton>
|
||||||
</RadioButton>
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="20dp"
|
android:layout_marginLeft="20dp"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="20sp" >
|
android:textSize="20sp"></TextView>
|
||||||
</TextView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -15,6 +15,7 @@
|
|||||||
android:text="第一:"
|
android:text="第一:"
|
||||||
android:textColor="#ebf657"
|
android:textColor="#ebf657"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/identify_item_user"
|
android:id="@+id/identify_item_user"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -23,6 +24,7 @@
|
|||||||
android:text="18505511338"
|
android:text="18505511338"
|
||||||
android:textColor="#ebf657"
|
android:textColor="#ebf657"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/identify_item_score"
|
android:id="@+id/identify_item_score"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -6,13 +6,5 @@
|
|||||||
android:descendantFocusability="blocksDescendants"
|
android:descendantFocusability="blocksDescendants"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btn"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="@dimen/margin_"
|
|
||||||
android:layout_marginRight="@dimen/margin_"
|
|
||||||
android:layout_marginTop="@dimen/pading_"
|
|
||||||
android:textSize="@dimen/btn_size" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -8,23 +8,96 @@
|
|||||||
<include layout="@layout/title" />
|
<include layout="@layout/title" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/edit_text"
|
android:id="@+id/tip"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/margin_"
|
android:layout_marginLeft="@dimen/margin_"
|
||||||
android:layout_marginRight="@dimen/margin_"
|
android:layout_marginRight="@dimen/margin_"
|
||||||
|
android:textColor="@color/white"
|
||||||
android:textSize="@dimen/txt_size" />
|
android:textSize="@dimen/txt_size" />
|
||||||
|
|
||||||
<ListView
|
<ScrollView
|
||||||
android:id="@+id/listview_main"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:orientation="vertical">
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:layout_marginRight="5dp"
|
<Button
|
||||||
android:cacheColorHint="@color/white"
|
android:id="@+id/iatBtn"
|
||||||
android:divider="@drawable/line_background"
|
android:layout_width="match_parent"
|
||||||
android:dividerHeight="@dimen/line_height"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="5dp" />
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验语音听写"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/asrBtn"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验语法识别"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/nlpBtn"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验语义理解"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/ttsBtn"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验语音合成"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/iseBtn"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验语音评测"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/faceBtn"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="立刻体验人脸识别"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/btn_size" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -53,7 +53,6 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="10dp"
|
android:layout_margin="10dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textColor="@color/white"
|
||||||
android:text="讯飞语音示例"
|
android:text="讯飞语音示例"
|
||||||
android:textSize="30sp" />
|
android:textSize="30sp" />
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<drawable name="line_background">#161823</drawable>
|
<drawable name="line_background">#161823</drawable>
|
||||||
|
|
||||||
<color name="white">#FFFFFF</color>
|
<color name="white">#FFFFFF</color>
|
||||||
|
<color name="black">#000</color>
|
||||||
|
|
||||||
<!-- 控件按下时显示的颜色 -->
|
<!-- 控件按下时显示的颜色 -->
|
||||||
<color name="list_backgroud_color">#2fb3cb</color>
|
<color name="list_backgroud_color">#2fb3cb</color>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="dialog" parent="@android:style/Theme.Dialog">
|
<style name="dialog" parent="@android:style/Theme.Dialog">
|
||||||
<item name="android:windowFrame">@null</item>
|
<item name="android:windowFrame">@null</item>
|
||||||
<item name="android:windowIsFloating">true</item>
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user