滨化讯飞插件

This commit is contained in:
万昕放 2022-11-19 10:53:39 +08:00
parent f46962da29
commit 5e5aed2682
70 changed files with 4339 additions and 4506 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,14 +1,13 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '26.0.2'
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.iflytek.voicedemo"
minSdkVersion 9
targetSdkVersion 28
minSdkVersion 16
targetSdkVersion 30
}
buildTypes {
@ -26,17 +25,15 @@ android {
allprojects {
repositories {
jcenter()
google()
mavenCentral()
}
}
}
dependencies {
compile files('libs/Msc.jar')
// compile project(':MscLibSrc')
compile 'com.android.support:support-v4:23.+'
implementation files('libs/Msc.jar')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
}

View File

@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
</lint>
<lint></lint>

View File

@ -2,88 +2,81 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iflytek.voicedemo"
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
android:icon="@drawable/icon"
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
android:name="com.iflytek.voicedemo.MainActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:icon="@drawable/icon"
android:label="讯飞语音示例"
android:screenOrientation="portrait" >
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.iflytek.speech.setting.TtsSettings" >
</activity>
<activity android:name="com.iflytek.speech.setting.IatSettings" >
</activity>
<activity android:name="com.iflytek.speech.setting.TtsSettings" />
<activity android:name="com.iflytek.speech.setting.IatSettings" />
<activity
android:name="com.iflytek.voicedemo.IatDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.AsrDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.TtsDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.IseDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
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>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.faceonline.OnlineFaceDemo"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait">
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.IdentifyGroup.FaceIdentifyActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
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>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.voicedemo.IdentifyGroup.ResultIdentifyActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait">
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.speech.setting.IseSettings"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<activity
android:name="com.iflytek.speech.setting.UrlSettings"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="portrait" />
<!-- 移动统计分析 -->
<meta-data
android:name="IFLYTEK_APPKEY"
@ -95,20 +88,4 @@
</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>

View File

@ -3,10 +3,10 @@
*/
package com.iflytek.ise.result;
import java.util.ArrayList;
import com.iflytek.ise.result.entity.Sentence;
import java.util.ArrayList;
/**
* <p>Title: Result</p>
* <p>Description: 评测结果</p>

View File

@ -99,7 +99,7 @@ public class Phone {
public static String getStdSymbol(String content) {
String std = phone_map.get(content);
return (null == std)? content: std;
return (null == std) ? content : std;
}
}

View File

@ -3,13 +3,13 @@
*/
package com.iflytek.ise.result.util;
import java.util.ArrayList;
import com.iflytek.ise.result.entity.Phone;
import com.iflytek.ise.result.entity.Sentence;
import com.iflytek.ise.result.entity.Syll;
import com.iflytek.ise.result.entity.Word;
import java.util.ArrayList;
/**
* <p>Title: ResultFormatUtl</p>
* <p>Description: </p>
@ -31,7 +31,7 @@ public class ResultFormatUtil {
return buffer.toString();
}
for (Sentence sentence: sentences ) {
for (Sentence sentence : sentences) {
if ("噪音".equals(ResultTranslateUtil.getContent(sentence.content))
|| "静音".equals(ResultTranslateUtil.getContent(sentence.content))) {
continue;
@ -40,7 +40,7 @@ public class ResultFormatUtil {
if (null == sentence.words) {
continue;
}
for (Word word: sentence.words) {
for (Word word : sentence.words) {
if ("噪音".equals(ResultTranslateUtil.getContent(word.content))
|| "静音".equals(ResultTranslateUtil.getContent(word.content))) {
continue;
@ -54,13 +54,13 @@ public class ResultFormatUtil {
continue;
}
for (Syll syll: word.sylls) {
for (Syll syll : word.sylls) {
buffer.append("\n└音节[" + ResultTranslateUtil.getContent(syll.getStdSymbol()) + "] ");
if (null == syll.phones) {
continue;
}
for (Phone phone: syll.phones) {
for (Phone phone : syll.phones) {
buffer.append("\n\t└音素[" + ResultTranslateUtil.getContent(phone.getStdSymbol()) + "] ")
.append(" 朗读:" + ResultTranslateUtil.getDpMessageInfo(phone.dp_message));
}
@ -85,18 +85,18 @@ public class ResultFormatUtil {
return buffer.toString();
}
for (Sentence sentence: sentences ) {
for (Sentence sentence : sentences) {
if (null == sentence.words) {
continue;
}
for (Word word: sentence.words) {
for (Word word : sentence.words) {
buffer.append("\n词语[" + ResultTranslateUtil.getContent(word.content) + "] " + word.symbol + " 时长:" + word.time_len);
if (null == word.sylls) {
continue;
}
for (Syll syll: word.sylls) {
for (Syll syll : word.sylls) {
if ("噪音".equals(ResultTranslateUtil.getContent(syll.content))
|| "静音".equals(ResultTranslateUtil.getContent(syll.content))) {
continue;
@ -107,7 +107,7 @@ public class ResultFormatUtil {
continue;
}
for (Phone phone: syll.phones) {
for (Phone phone : syll.phones) {
buffer.append("\n\t└音素[" + ResultTranslateUtil.getContent(phone.content) + "] " + "时长:" + phone.time_len)
.append(" 朗读:" + ResultTranslateUtil.getDpMessageInfo(phone.dp_message));
}

View File

@ -35,6 +35,6 @@ public class ResultTranslateUtil {
public static String getContent(String content) {
String val = special_content_map.get(content);
return (null == val)? content: val;
return (null == val) ? content : val;
}
}

View File

@ -3,14 +3,6 @@
*/
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.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.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>Description: </p>
@ -109,7 +109,7 @@ public class XmlResultParser {
if (!rec_paperPassed) {
result = new ReadWordResult();
String lan = getLanguage(pullParser);
result.language = (null == lan)? "cn": lan;
result.language = (null == lan) ? "cn" : lan;
} else {
readTotalResult(result, pullParser);
}
@ -118,7 +118,7 @@ public class XmlResultParser {
if (!rec_paperPassed) {
result = new ReadSentenceResult();
String lan = getLanguage(pullParser);
result.language = (null == lan)? "cn": lan;
result.language = (null == lan) ? "cn" : lan;
} else {
readTotalResult(result, pullParser);
}

View File

@ -26,12 +26,13 @@ public class IatSettings extends PreferenceActivity implements OnPreferenceChang
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.iat_setting);
mVadbosPreference = (EditTextPreference)findPreference("iat_vadbos_preference");
mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadbosPreference,0,10000));
mVadbosPreference = (EditTextPreference) findPreference("iat_vadbos_preference");
mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadbosPreference, 0, 10000));
mVadeosPreference = (EditTextPreference)findPreference("iat_vadeos_preference");
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadeosPreference,0,10000));
mVadeosPreference = (EditTextPreference) findPreference("iat_vadeos_preference");
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadeosPreference, 0, 10000));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;

View File

@ -7,8 +7,8 @@ import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.text.InputType;
import android.text.TextUtils;
import android.view.Window;
@ -17,6 +17,8 @@ import android.widget.Toast;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.voicedemo.R;
import java.util.HashMap;
/**
* 评测设置界面
*/
@ -32,6 +34,9 @@ public class IseSettings extends PreferenceActivity {
private Toast mToast;
private HashMap<String, String> zhMap = new HashMap<>();
private HashMap<String, String> enMap = new HashMap<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -39,10 +44,27 @@ public class IseSettings extends PreferenceActivity {
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.ise_settings);
initCategoryMap();
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() {
mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE);
mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY);
@ -70,14 +92,23 @@ public class IseSettings extends PreferenceActivity {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String categoryValue = mCategoryPref.getValue();
if ("zh_cn".equals(newValue.toString())) {
// 中文
if ("plain".equals(mResultLevelPref.getValue())) {
showTip("汉语评测结果格式不支持plain设置");
return false;
}
if (!zhMap.containsKey(categoryValue)) {
showTip("中文评测不支持" + enMap.get(categoryValue));
return false;
}
} else {
if ("read_syllable".equals(mCategoryPref.getValue())) {
showTip("英语评测不支持单字");
// 英文
if (!enMap.containsKey(categoryValue)) {
showTip("英语评测不支持" + zhMap.get(categoryValue));
return false;
}
}
@ -93,10 +124,20 @@ public class IseSettings extends PreferenceActivity {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ("en_us".equals(mLanguagePref.getValue()) && "read_syllable".equals(newValue.toString())) {
showTip("英语评测不支持单字,请选其他项");
String categoryValue = newValue.toString();
if ("en_us".equals(mLanguagePref.getValue())) {
if (!enMap.containsKey(categoryValue)) {
showTip("英语评测不支持" + zhMap.get(categoryValue) + ",请选其他项");
return false;
}
}
if ("zh_cn".equals(mLanguagePref.getValue())) {
if (!zhMap.containsKey(categoryValue)) {
showTip("中文评测不支持" + enMap.get(categoryValue) + ",请选其他项");
return false;
}
}
int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString());
String newEntry = (String) mCategoryPref.getEntries()[newValueIndex];
@ -163,7 +204,7 @@ public class IseSettings extends PreferenceActivity {
}
});
mSpeechTimeoutPref.getEditText().setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_CLASS_NUMBER);
mSpeechTimeoutPref.getEditText().setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);
mSpeechTimeoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
@ -193,7 +234,8 @@ public class IseSettings extends PreferenceActivity {
}
private void showTip(String str) {
if(!TextUtils.isEmpty(str)) {
if (!TextUtils.isEmpty(str)) {
mToast.cancel();
mToast.setText(str);
mToast.show();
}

View File

@ -29,14 +29,14 @@ public class TtsSettings extends PreferenceActivity implements OnPreferenceChang
// 指定保存文件名字
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.tts_setting);
mSpeedPreference = (EditTextPreference)findPreference("speed_preference");
mSpeedPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mSpeedPreference,0,200));
mSpeedPreference = (EditTextPreference) findPreference("speed_preference");
mSpeedPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mSpeedPreference, 0, 200));
mPitchPreference = (EditTextPreference)findPreference("pitch_preference");
mPitchPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mPitchPreference,0,100));
mPitchPreference = (EditTextPreference) findPreference("pitch_preference");
mPitchPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mPitchPreference, 0, 100));
mVolumePreference = (EditTextPreference)findPreference("volume_preference");
mVolumePreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mVolumePreference,0,100));
mVolumePreference = (EditTextPreference) findPreference("volume_preference");
mVolumePreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this, mVolumePreference, 0, 100));
}

View File

@ -1,18 +1,15 @@
package com.iflytek.speech.setting;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.support.annotation.Nullable;
import android.view.Window;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.voicedemo.R;
import androidx.annotation.Nullable;
import java.util.List;
import com.iflytek.voicedemo.R;
/**
* @author hjyu
@ -33,7 +30,7 @@ public class UrlSettings extends PreferenceActivity implements Preference.OnPref
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
addPreferencesFromResource(R.xml.url_setting);
url_preference = (ListPreference)findPreference("url_preference");
url_preference = (ListPreference) findPreference("url_preference");
url_preference.setSummary("当前:" + url_preference.getEntry());
url_preference.setOnPreferenceChangeListener(this);

View File

@ -3,6 +3,8 @@ package com.iflytek.speech.util;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@ -13,14 +15,17 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Environment;
import android.os.Build;
import android.provider.MediaStore;
import androidx.core.content.FileProvider;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;
public class FaceUtil {
@ -28,6 +33,19 @@ public class FaceUtil {
public final static int REQUEST_CAMERA_IMAGE = 2;
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
@ -41,35 +59,40 @@ public class FaceUtil {
innerIntent.putExtra("aspectY", 1);// 放大缩小比例的X 这里的比例为 1:1
innerIntent.putExtra("outputX", 320); //这个是限制输出图片大小
innerIntent.putExtra("outputY", 320);
innerIntent.putExtra("return-data", true);
innerIntent.putExtra("return-data", false);
// 切图大小不足输出无黑框
innerIntent.putExtra("scale", true);
innerIntent.putExtra("scaleUpIfNeeded", true);
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());
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);
}
/**
* 保存裁剪的图片的路径
*
* @return
*/
public static String getImagePath(Context context){
String path;
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
path = context.getFilesDir().getAbsolutePath();
} else {
path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/msc/";
}
if(!path.endsWith("/")) {
public static String getImagePath(Context context) {
String path = context.getExternalFilesDir("msc").getAbsolutePath();
if (!path.endsWith("/")) {
path += "/";
}
File folder = new File(path);
if (folder != null && !folder.exists()) {
if (!folder.exists()) {
folder.mkdirs();
}
path += "ifd.jpg";
@ -134,7 +157,7 @@ public class FaceUtil {
* @param DrawOriRect 可绘制原始框也可以只画四个角
*/
static public void drawFaceRect(Canvas canvas, FaceRect face, int width, int height, boolean frontCamera, boolean DrawOriRect) {
if(canvas == null) {
if (canvas == null) {
return;
}
@ -146,7 +169,7 @@ public class FaceUtil {
Rect rect = face.bound;
if(frontCamera) {
if (frontCamera) {
int top = rect.top;
rect.top = width - rect.bottom;
rect.bottom = width - top;
@ -161,20 +184,19 @@ public class FaceUtil {
int drawu = rect.top - len;
int drawd = rect.bottom + len;
canvas.drawLine(drawl,drawd,drawl,drawd-len, paint);
canvas.drawLine(drawl,drawd,drawl+len,drawd, paint);
canvas.drawLine(drawr,drawd,drawr,drawd-len, paint);
canvas.drawLine(drawr,drawd,drawr-len,drawd, paint);
canvas.drawLine(drawl,drawu,drawl,drawu+len, paint);
canvas.drawLine(drawl,drawu,drawl+len,drawu, paint);
canvas.drawLine(drawr,drawu,drawr,drawu+len, paint);
canvas.drawLine(drawr,drawu,drawr-len,drawu, paint);
canvas.drawLine(drawl, drawd, drawl, drawd - len, paint);
canvas.drawLine(drawl, drawd, drawl + len, drawd, paint);
canvas.drawLine(drawr, drawd, drawr, drawd - len, paint);
canvas.drawLine(drawr, drawd, drawr - len, drawd, paint);
canvas.drawLine(drawl, drawu, drawl, drawu + len, paint);
canvas.drawLine(drawl, drawu, drawl + len, drawu, paint);
canvas.drawLine(drawr, drawu, drawr, drawu + len, paint);
canvas.drawLine(drawr, drawu, drawr - len, drawu, paint);
}
if (face.point != null) {
for (Point p : face.point)
{
if(frontCamera) {
for (Point p : face.point) {
if (frontCamera) {
p.y = width - p.y;
}
canvas.drawPoint(p.x, p.y, paint);
@ -185,40 +207,27 @@ public class FaceUtil {
/**
* 将矩形随原图顺时针旋转90度
*
* @param r
* 待旋转的矩形
*
* @param width
* 输入矩形对应的原图宽
*
* @param height
* 输入矩形对应的原图高
*
* @return
* 旋转后的矩形
* @param r 待旋转的矩形
* @param width 输入矩形对应的原图宽
* @param height 输入矩形对应的原图高
* @return 旋转后的矩形
*/
static public Rect RotateDeg90(Rect r, int width, int height) {
int left = r.left;
r.left = height- r.bottom;
r.bottom= r.right;
r.right = height- r.top;
r.left = height - r.bottom;
r.bottom = r.right;
r.right = height - r.top;
r.top = left;
return r;
}
/**
* 将点随原图顺时针旋转90度
* @param p
* 待旋转的点
*
* @param width
* 输入点对应的原图宽
*
* @param height
* 输入点对应的原图宽
*
* @return
* 旋转后的点
* @param p 待旋转的点
* @param width 输入点对应的原图宽
* @param height 输入点对应的原图宽
* @return 旋转后的点
*/
static public Point RotateDeg90(Point p, int width, int height) {
int x = p.x;
@ -231,7 +240,7 @@ public class FaceUtil {
class CpuFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
if(Pattern.matches("cpu[0-9]", pathname.getName())) {
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
@ -241,7 +250,7 @@ public class FaceUtil {
File dir = new File("/sys/devices/system/cpu/");
File[] files = dir.listFiles(new CpuFilter());
return files.length;
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
return 1;
}
@ -249,9 +258,8 @@ public class FaceUtil {
/**
* 保存Bitmap至本地
* @param Bitmap
*/
public static void saveBitmapToFile(Context context,Bitmap bmp){
public static void saveBitmapToFile(Context context, Bitmap bmp) {
String file_path = getImagePath(context);
File file = new File(file_path);
FileOutputStream fOut;

View File

@ -1,16 +1,17 @@
package com.iflytek.speech.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.SpeechConstant;
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,12 +19,12 @@ import android.content.Context;
public class FucUtil {
/**
* 读取asset目录下文件
*
* @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;
byte []buf = null;
byte[] buf = null;
String result = "";
try {
InputStream in = mContext.getAssets().open(file);
@ -31,51 +32,50 @@ public class FucUtil {
buf = new byte[len];
in.read(buf, 0, len);
result = new String(buf,code);
result = new String(buf, code);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 将字节缓冲区按照固定大小进行分割成数组
*
* @param buffer 缓冲区
* @param length 缓冲区大小
* @param spsize 切割块大小
* @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[]>();
if(spsize <= 0 || length <= 0 || buffer == null || buffer.length < length)
if (spsize <= 0 || length <= 0 || buffer == null || buffer.length < length)
return array;
int size = 0;
while(size < length)
{
while (size < length) {
int left = length - size;
if(spsize < left)
{
if (spsize < left) {
byte[] sdata = new byte[spsize];
System.arraycopy(buffer,size,sdata,0,spsize);
System.arraycopy(buffer, size, sdata, 0, spsize);
array.add(sdata);
size += spsize;
}else
{
} else {
byte[] sdata = new byte[left];
System.arraycopy(buffer,size,sdata,0,left);
System.arraycopy(buffer, size, sdata, 0, left);
array.add(sdata);
size += left;
}
}
return array;
}
/**
* 获取语记是否包含离线听写资源如未包含跳转至资源下载页面
*1.PLUS_LOCAL_ALL: 本地所有资源
2.PLUS_LOCAL_ASR: 本地识别资源
3.PLUS_LOCAL_TTS: 本地合成资源
* 1.PLUS_LOCAL_ALL: 本地所有资源
* 2.PLUS_LOCAL_ASR: 本地识别资源
* 3.PLUS_LOCAL_TTS: 本地合成资源
*/
public static String checkLocalResource(){
public static String checkLocalResource() {
String resource = SpeechUtility.getUtility().getParameter(SpeechConstant.PLUS_LOCAL_ASR);
try {
JSONObject result = new JSONObject(resource);
@ -87,7 +87,7 @@ public class FucUtil {
int i = 0;
// 查询否包含离线听写资源
for (; i < asrArray.length(); i++) {
if("iat".equals(asrArray.getJSONObject(i).get(SpeechConstant.DOMAIN))){
if ("iat".equals(asrArray.getJSONObject(i).get(SpeechConstant.DOMAIN))) {
//asrArray中包含语言方言字段后续会增加支持方言的本地听写
//"accent": "mandarin","language": "zh_cn"
break;
@ -98,7 +98,7 @@ public class FucUtil {
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
return "没有听写资源,跳转至资源下载页面";
}
}else {
} else {
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
return "没有听写资源,跳转至资源下载页面";
}

View File

@ -4,8 +4,6 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import android.util.Log;
/**
* Json结果解析类
*/
@ -36,6 +34,66 @@ public class JsonParser {
return ret.toString();
}
public static String parseGrammarResult(String json, String engType) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);
JSONArray words = joResult.getJSONArray("ws");
// 云端和本地结果分情况解析
if ("cloud".equals(engType)) {
for (int i = 0; i < words.length(); i++) {
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
for (int j = 0; j < items.length(); j++) {
JSONObject obj = items.getJSONObject(j);
if (obj.getString("w").contains("nomatch")) {
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append("【结果】" + obj.getString("w"));
ret.append("【置信度】" + obj.getInt("sc"));
ret.append("\n");
}
}
} else if ("local".equals(engType)) {
ret.append("【结果】");
for (int i = 0; i < words.length(); i++) {
JSONObject wsItem = words.getJSONObject(i);
JSONArray items = wsItem.getJSONArray("cw");
if ("<contact>".equals(wsItem.getString("slot"))) {
// 可能会有多个联系人供选择用中括号括起来这些候选项具有相同的置信度
ret.append("");
for (int j = 0; j < items.length(); j++) {
JSONObject obj = items.getJSONObject(j);
if (obj.getString("w").contains("nomatch")) {
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append(obj.getString("w")).append("|");
}
ret.setCharAt(ret.length() - 1, '】');
} else {
//本地多候选按照置信度高低排序一般选取第一个结果即可
JSONObject obj = items.getJSONObject(0);
if (obj.getString("w").contains("nomatch")) {
ret.append("没有匹配结果.");
return ret.toString();
}
ret.append(obj.getString("w"));
}
}
ret.append("【置信度】" + joResult.getInt("sc"));
ret.append("\n");
}
} catch (Exception e) {
e.printStackTrace();
ret.append("没有匹配结果.");
}
return ret.toString();
}
public static String parseGrammarResult(String json) {
StringBuffer ret = new StringBuffer();
try {
@ -45,11 +103,9 @@ public class JsonParser {
JSONArray words = joResult.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
for(int j = 0; j < items.length(); j++)
{
for (int j = 0; j < items.length(); j++) {
JSONObject obj = items.getJSONObject(j);
if(obj.getString("w").contains("nomatch"))
{
if (obj.getString("w").contains("nomatch")) {
ret.append("没有匹配结果.");
return ret.toString();
}
@ -74,11 +130,9 @@ public class JsonParser {
JSONArray words = joResult.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
for(int j = 0; j < items.length(); j++)
{
for (int j = 0; j < items.length(); j++) {
JSONObject obj = items.getJSONObject(j);
if(obj.getString("w").contains("nomatch"))
{
if (obj.getString("w").contains("nomatch")) {
ret.append("没有匹配结果.");
return ret.toString();
}
@ -95,13 +149,13 @@ public class JsonParser {
return ret.toString();
}
public static String parseTransResult(String json,String key) {
public static String parseTransResult(String json, String key) {
StringBuffer ret = new StringBuffer();
try {
JSONTokener tokener = new JSONTokener(json);
JSONObject joResult = new JSONObject(tokener);
String errorCode = joResult.optString("ret");
if(!errorCode.equals("0")) {
if (!errorCode.equals("0")) {
return joResult.optString("errmsg");
}
JSONObject transResult = joResult.optJSONObject("trans_result");

View File

@ -1,6 +1,5 @@
package com.iflytek.speech.util;
import java.util.regex.Pattern;
import android.content.Context;
import android.preference.EditTextPreference;
import android.text.Editable;
@ -8,18 +7,20 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Toast;
import java.util.regex.Pattern;
/**
* 输入框输入范围控制
*/
public class SettingTextWatcher implements TextWatcher {
private int editStart ;
private int editCount ;
private int editStart;
private int editCount;
private EditTextPreference mEditTextPreference;
int minValue;//最小值
int maxValue;//最大值
private Context mContext;
public SettingTextWatcher(Context context,EditTextPreference e,int min, int max) {
public SettingTextWatcher(Context context, EditTextPreference e, int min, int max) {
mContext = context;
mEditTextPreference = e;
minValue = min;
@ -34,7 +35,7 @@ public class SettingTextWatcher implements TextWatcher {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Log.e("demo", "beforeTextChanged start:"+start+" count:"+count+" after:"+after);
}
@ -48,12 +49,12 @@ public class SettingTextWatcher implements TextWatcher {
if (isNumeric(content)) {
int num = Integer.parseInt(content);
if (num > maxValue || num < minValue) {
s.delete(editStart, editStart+editCount);
s.delete(editStart, editStart + editCount);
mEditTextPreference.getEditText().setText(s);
Toast.makeText(mContext, "超出有效值范围", Toast.LENGTH_SHORT).show();
}
}else {
s.delete(editStart, editStart+editCount);
} else {
s.delete(editStart, editStart + editCount);
mEditTextPreference.getEditText().setText(s);
Toast.makeText(mContext, "只能输入数字哦", Toast.LENGTH_SHORT).show();
}
@ -62,7 +63,7 @@ public class SettingTextWatcher implements TextWatcher {
/**
* 正则表达式-判断是否为数字
*/
public static boolean isNumeric(String str){
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}

View File

@ -1,23 +1,22 @@
package com.iflytek.speech.util;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Xml结果解析类
*/
public class XmlParser {
public static String parseNluResult(String xml)
{
public static String parseNluResult(String xml) {
StringBuffer buffer = new StringBuffer();
try
{
try {
// DOM builder
DocumentBuilder domBuilder = null;
// DOM doc
@ -32,25 +31,24 @@ public class XmlParser {
// 获取根节点
Element root = (Element) domDoc.getDocumentElement();
Element raw = (Element)root.getElementsByTagName("rawtext").item(0);
Element raw = (Element) root.getElementsByTagName("rawtext").item(0);
buffer.append("【识别结果】" + raw.getFirstChild().getNodeValue());
buffer.append("\n");
Element e = (Element)root.getElementsByTagName("result").item(0);
Element e = (Element) root.getElementsByTagName("result").item(0);
Element focus = (Element)e.getElementsByTagName("focus").item(0);
Element focus = (Element) e.getElementsByTagName("focus").item(0);
buffer.append("【FOCUS】" + focus.getFirstChild().getNodeValue());
buffer.append("\n");
Element action = (Element)e.getElementsByTagName("action").item(0);
Element operation = (Element)action.getElementsByTagName("operation").item(0);
Element action = (Element) e.getElementsByTagName("action").item(0);
Element operation = (Element) action.getElementsByTagName("operation").item(0);
buffer.append("【ACTION】" + operation.getFirstChild().getNodeValue());
buffer.append("\n");
}catch(Exception e){
} catch (Exception e) {
e.printStackTrace();
};
}
buffer.append("【ALL】" + xml);
return buffer.toString();
}

View File

@ -5,21 +5,17 @@ import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.GrammarListener;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.LexiconListener;
import com.iflytek.cloud.RecognizerListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
@ -27,12 +23,11 @@ import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.iflytek.speech.util.FucUtil;
import com.iflytek.speech.util.JsonParser;
/*import com.iflytek.sunflower.FlowerCollector;*/
/**
* 识别示例
*/
public class AsrDemo extends Activity implements OnClickListener{
public class AsrDemo extends Activity implements OnClickListener {
private static String TAG = AsrDemo.class.getSimpleName();
// 语音识别对象
private SpeechRecognizer mAsr;
@ -57,11 +52,9 @@ public class AsrDemo extends Activity implements OnClickListener{
// 初始化识别对象
mAsr = SpeechRecognizer.createRecognizer(AsrDemo.this, mInitListener);
mCloudGrammar = FucUtil.readFile(this,"grammar_sample.abnf","utf-8");
mCloudGrammar = FucUtil.readFile(this, "grammar_sample.abnf", "utf-8");
mSharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
}
/**
@ -76,49 +69,47 @@ public class AsrDemo extends Activity implements OnClickListener{
}
// 语法词典临时变量
String mContent;
private String mContent;
// 函数调用返回值
int ret = 0;
private int ret = 0;
@Override
public void onClick(View view) {
if( null == mAsr ){
if (null == mAsr) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
this.showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
if(null == mEngineType) {
if (null == mEngineType) {
showTip("请先选择识别引擎类型");
return;
}
switch(view.getId())
{
switch (view.getId()) {
case R.id.isr_grammar:
showTip("上传预设关键词/语法文件");
// 在线-构建语法文件生成语法id
((EditText)findViewById(R.id.isr_text)).setText(mCloudGrammar);
((EditText) findViewById(R.id.isr_text)).setText(mCloudGrammar);
mContent = new String(mCloudGrammar);
//指定引擎类型
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);
if(ret != ErrorCode.SUCCESS)
showTip("语法构建失败,错误码:" + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
if (ret != ErrorCode.SUCCESS) {
showTip("语法构建失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
break;
// 开始识别
case R.id.isr_recognize:
((EditText)findViewById(R.id.isr_text)).setText(null);// 清空显示内容
((EditText) findViewById(R.id.isr_text)).setText(null);// 清空显示内容
// 设置参数
if (!setParam()) {
showTip("请先构建语法。");
return;
};
}
ret = mAsr.startListening(mRecognizerListener);
if (ret != ErrorCode.SUCCESS) {
showTip("识别失败,错误码: " + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("识别失败,错误码: " + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
break;
// 停止识别
@ -143,21 +134,7 @@ public class AsrDemo extends Activity implements OnClickListener{
public void onInit(int code) {
Log.d(TAG, "SpeechRecognizer init() code = " + code);
if (code != ErrorCode.SUCCESS) {
showTip("初始化失败,错误码:"+code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
};
/**
* 更新词典监听器
*/
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查询解决方案");
showTip("初始化失败,错误码:" + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
};
@ -168,15 +145,15 @@ public class AsrDemo extends Activity implements OnClickListener{
private GrammarListener mCloudGrammarListener = new GrammarListener() {
@Override
public void onBuildFinish(String grammarId, SpeechError error) {
if(error == null){
if (error == null) {
String grammarID = new String(grammarId);
Editor editor = mSharedPreferences.edit();
if(!TextUtils.isEmpty(grammarId))
if (!TextUtils.isEmpty(grammarId))
editor.putString(KEY_GRAMMAR_ABNF_ID, grammarID);
editor.commit();
showTip("语法构建成功:" + grammarId);
}else{
showTip("语法构建失败,错误码:" + error.getErrorCode()+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
} else {
showTip("语法构建失败,错误码:" + error.getErrorCode() + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
};
@ -189,22 +166,22 @@ public class AsrDemo extends Activity implements OnClickListener{
@Override
public void onVolumeChanged(int volume, byte[] data) {
showTip("当前正在说话,音量大小:" + volume);
Log.d(TAG, "返回音频数据:"+data.length);
Log.d(TAG, "返回音频数据:" + data.length);
}
@Override
public void onResult(final RecognizerResult result, boolean isLast) {
if (null != result) {
Log.d(TAG, "recognizer result" + result.getResultString());
String text ;
if("cloud".equalsIgnoreCase(mEngineType)){
String text;
if ("cloud".equalsIgnoreCase(mEngineType)) {
text = JsonParser.parseGrammarResult(result.getResultString());
}else {
} else {
text = JsonParser.parseLocalGrammarResult(result.getResultString());
}
// 显示
((EditText)findViewById(R.id.isr_text)).setText(text);
((EditText) findViewById(R.id.isr_text)).setText(text);
} else {
Log.d(TAG, "recognizer result : null");
}
@ -240,12 +217,14 @@ public class AsrDemo extends Activity implements OnClickListener{
};
private void showTip(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mToast.setText(str);
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
mToast.show();
}
});
@ -253,31 +232,30 @@ public class AsrDemo extends Activity implements OnClickListener{
/**
* 参数设置
*
* @return
*/
public boolean setParam(){
public boolean setParam() {
boolean result = false;
//设置识别引擎
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
//设置返回结果为json格式
mAsr.setParameter(SpeechConstant.RESULT_TYPE, "json");
if("cloud".equalsIgnoreCase(mEngineType))
{
if ("cloud".equalsIgnoreCase(mEngineType)) {
String grammarId = mSharedPreferences.getString(KEY_GRAMMAR_ABNF_ID, null);
if(TextUtils.isEmpty(grammarId))
{
if (TextUtils.isEmpty(grammarId)) {
result = false;
}else {
} else {
//设置云端识别使用的语法id
mAsr.setParameter(SpeechConstant.CLOUD_GRAMMAR, grammarId);
result = true;
}
}
// 设置音频保存路径保存音频格式支持pcmwav设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
mAsr.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
mAsr.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/asr.wav");
// 设置音频保存路径保存音频格式支持pcmwav
mAsr.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
mAsr.setParameter(SpeechConstant.ASR_AUDIO_PATH,
getExternalFilesDir("msc").getAbsolutePath() + "/asr.wav");
return result;
}
@ -285,27 +263,11 @@ public class AsrDemo extends Activity implements OnClickListener{
protected void onDestroy() {
super.onDestroy();
if( null != mAsr ){
if (null != mAsr) {
// 退出时释放连接
mAsr.cancel();
mAsr.destroy();
}
}
@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();
}
}

View File

@ -1,12 +1,5 @@
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.app.Activity;
import android.app.AlertDialog;
@ -14,10 +7,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
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.view.View;
import android.view.View.OnClickListener;
@ -36,12 +25,17 @@ import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.iflytek.cloud.ui.RecognizerDialog;
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.util.FucUtil;
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 {
private static String TAG = IatDemo.class.getSimpleName();
@ -50,7 +44,7 @@ public class IatDemo extends Activity implements OnClickListener {
// 语音听写UI
private RecognizerDialog mIatDialog;
// 用HashMap存储听写结果
private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
private HashMap<String, String> mIatResults = new LinkedHashMap<>();
private EditText mResultText;
private EditText showContacts;
@ -60,31 +54,16 @@ public class IatDemo extends Activity implements OnClickListener {
// 引擎类型
private String mEngineType = SpeechConstant.TYPE_CLOUD;
private String[] languageEntries ;
private String[] languageEntries;
private String[] languageValues;
private String language="zh_cn";
private int selectedNum=0;
private String language = "zh_cn";
private int selectedNum = 0;
private String resultType = "json";
private boolean cyclic = false;//音频流识别是否循环调用
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) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -103,21 +82,17 @@ public class IatDemo extends Activity implements OnClickListener {
mSharedPreferences = getSharedPreferences(IatSettings.PREFER_NAME,
Activity.MODE_PRIVATE);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
mResultText = ((EditText) findViewById(R.id.iat_text));
showContacts = (EditText) findViewById(R.id.iat_contacts);
}
/**
* 初始化Layout
*/
private void initLayout() {
findViewById(R.id.iat_recognize).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_stop).setOnClickListener(IatDemo.this);
findViewById(R.id.iat_cancel).setOnClickListener(IatDemo.this);
@ -129,9 +104,9 @@ public class IatDemo extends Activity implements OnClickListener {
@Override
public void onClick(View view) {
if( null == mIat ){
if (null == mIat) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
this.showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
@ -144,9 +119,6 @@ public class IatDemo extends Activity implements OnClickListener {
// 开始听写
// 如何判断一次听写结束OnResult isLast=true 或者 onError
case R.id.iat_recognize:
// 移动数据分析收集开始听写事件
// FlowerCollector.onEvent(IatDemo.this, "iat_recognize");
buffer.setLength(0);
mResultText.setText(null);// 清空显示内容
mIatResults.clear();
@ -163,7 +135,7 @@ public class IatDemo extends Activity implements OnClickListener {
// 不显示听写对话框
ret = mIat.startListening(mRecognizerListener);
if (ret != ErrorCode.SUCCESS) {
showTip("听写失败,错误码:" + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("听写失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
} else {
showTip(getString(R.string.text_begin));
}
@ -186,25 +158,16 @@ public class IatDemo extends Activity implements OnClickListener {
mIat.cancel();
showTip("取消听写");
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:
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);
// 指定引擎类型
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
mIat.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
ret = mIat.updateLexicon("userword", contents, mLexiconListener);
if (ret != ErrorCode.SUCCESS)
showTip("上传热词失败,错误码:" + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("上传热词失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
break;
default:
break;
@ -220,7 +183,7 @@ public class IatDemo extends Activity implements OnClickListener {
public void onInit(int code) {
Log.d(TAG, "SpeechRecognizer init() code = " + code);
if (code != ErrorCode.SUCCESS) {
showTip("初始化失败,错误码:" + code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("初始化失败,错误码:" + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
};
@ -234,9 +197,10 @@ public class IatDemo extends Activity implements OnClickListener {
* <item>es_es</item> 西班牙语
* <item>fr_fr</item> 法语
* <item>ko_kr</item> 韩语
*
* @param v
*/
private void setLanguage(View v){
private void setLanguage(View v) {
new AlertDialog.Builder(v.getContext()).setTitle("语种语言种类")
.setSingleChoiceItems(languageEntries, // 单选框有几项,各是什么名字
0, // 默认的选项
@ -244,7 +208,7 @@ public class IatDemo extends Activity implements OnClickListener {
public void onClick(DialogInterface dialog,
int which) { // 点击了哪一项
language = languageValues[which];
((TextView)findViewById(R.id.languageText)).setText("你选择的是:"+languageEntries[which]);
((TextView) findViewById(R.id.languageText)).setText("你选择的是:" + languageEntries[which]);
selectedNum = which;
dialog.dismiss();
}
@ -282,7 +246,7 @@ public class IatDemo extends Activity implements OnClickListener {
public void onError(SpeechError error) {
// Tips
// 错误码10118(您没有说话)可能是录音机权限被禁需要提示用户打开应用的录音权限
Log.d(TAG, "onError " + error.getPlainDescription(true));
showTip(error.getPlainDescription(true));
}
@ -296,29 +260,23 @@ public class IatDemo extends Activity implements OnClickListener {
@Override
public void onResult(RecognizerResult results, boolean isLast) {
Log.d(TAG, results.getResultString());
System.out.println(flg++);
if (isLast) {
Log.d(TAG, "onResult 结束");
}
if (resultType.equals("json")) {
printResult(results);
}else if(resultType.equals("plain")) {
return;
}
if (resultType.equals("plain")) {
buffer.append(results.getResultString());
mResultText.setText(buffer.toString());
mResultText.setSelection(mResultText.length());
}
if (isLast & cyclic) {
// TODO 最后的结果
Message message = Message.obtain();
message.what = 0x001;
han.sendMessageDelayed(message,100);
}
}
@Override
public void onVolumeChanged(int volume, byte[] data) {
showTip("当前正在说话,音量大小:" + volume);
Log.d(TAG, "返回音频数据:"+data.length);
showTip("当前正在说话,音量大小 = " + volume + " 返回音频数据 = " + data.length);
}
@Override
@ -332,9 +290,11 @@ public class IatDemo extends Activity implements OnClickListener {
}
};
/**
* 显示结果
*/
private void printResult(RecognizerResult results) {
String text = JsonParser.parseIatResult(results.getResultString());
String sn = null;
// 读取json结果中的sn字段
try {
@ -350,7 +310,6 @@ public class IatDemo extends Activity implements OnClickListener {
for (String key : mIatResults.keySet()) {
resultBuffer.append(mIatResults.get(key));
}
mResultText.setText(resultBuffer.toString());
mResultText.setSelection(mResultText.length());
}
@ -359,50 +318,24 @@ public class IatDemo extends Activity implements OnClickListener {
* 听写UI监听器
*/
private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() {
// 返回结果
public void onResult(RecognizerResult results, boolean isLast) {
printResult(results);
}
/**
* 识别回调错误.
*/
// 识别回调错误
public void onError(SpeechError error) {
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) {
mToast.setText(str);
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
mToast.show();
}
@ -414,25 +347,23 @@ public class IatDemo extends Activity implements OnClickListener {
public void setParam() {
// 清空参数
mIat.setParameter(SpeechConstant.PARAMS, null);
// 设置听写引擎
mIat.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
// 设置返回结果格式
mIat.setParameter(SpeechConstant.RESULT_TYPE, resultType);
if(language.equals("zh_cn")) {
if (language.equals("zh_cn")) {
String lag = mSharedPreferences.getString("iat_language_preference",
"mandarin");
Log.e(TAG,"language:"+language);// 设置语言
// 设置语言
Log.e(TAG, "language = " + language);
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
// 设置语言区域
mIat.setParameter(SpeechConstant.ACCENT, lag);
}else {
} else {
mIat.setParameter(SpeechConstant.LANGUAGE, language);
}
Log.e(TAG,"last language:"+mIat.getParameter(SpeechConstant.LANGUAGE));
Log.e(TAG, "last language:" + mIat.getParameter(SpeechConstant.LANGUAGE));
//此处用于设置dialog中不显示错误码信息
//mIat.setParameter("view_tips_plain","false");
@ -446,39 +377,15 @@ public class IatDemo extends Activity implements OnClickListener {
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1"));
// 设置音频保存路径保存音频格式支持pcmwav设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
mIat.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/iat.wav");
// 设置音频保存路径保存音频格式支持pcmwav.
mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "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() {
buffer.setLength(0);
mResultText.setText(null);// 清空显示内容
@ -489,36 +396,33 @@ public class IatDemo extends Activity implements OnClickListener {
mIat.setParameter(SpeechConstant.AUDIO_SOURCE, "-1");
// 也可以像以下这样直接设置音频文件路径识别要求设置文件在sdcard上的全路径
// mIat.setParameter(SpeechConstant.AUDIO_SOURCE, "-2");
//mIat.setParameter(SpeechConstant.ASR_SOURCE_PATH, "sdcard/XXX/XXX.pcm");
// mIat.setParameter(SpeechConstant.ASR_SOURCE_PATH, "sdcard/XXX/XXX.pcm");
ret = mIat.startListening(mRecognizerListener);
if (ret != ErrorCode.SUCCESS) {
showTip("识别失败,错误码:" + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
} else {
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){
showTip("识别失败,错误码:" + ret + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
return;
}
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.writeAudio(audioData, 0, audioData.length );
mIat.stopListening();*/
} else {
} catch (IOException e) {
mIat.cancel();
showTip("读取音频流失败");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mIat != null) {
// 退出时释放连接
mIat.cancel();
mIat.destroy();
}
}
}

View File

@ -14,7 +14,6 @@ import android.media.ExifInterface;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Gravity;
@ -32,9 +31,7 @@ import com.iflytek.cloud.IdentityVerifier;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.speech.util.FaceUtil;
import com.iflytek.voicedemo.R;
import com.iflytek.voicedemo.faceonline.OnlineFaceDemo;
import org.json.JSONException;
import org.json.JSONObject;
@ -51,7 +48,7 @@ import java.io.IOException;
* @author hjyu
* @date 2017/9/28.
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
* */
*/
public class FaceIdentifyActivity extends Activity implements OnClickListener {
private final static String TAG = FaceIdentifyActivity.class.getSimpleName();
@ -91,7 +88,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
if (ErrorCode.SUCCESS == errorCode) {
showTip("引擎初始化成功");
} else {
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("引擎初始化失败,错误码:" + errorCode + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
});
@ -104,7 +101,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
findViewById(R.id.online_pick).setOnClickListener(FaceIdentifyActivity.this);
findViewById(R.id.online_camera).setOnClickListener(FaceIdentifyActivity.this);
findViewById(R.id.btn_identity).setOnClickListener(FaceIdentifyActivity.this);
txt_groupid = (TextView)findViewById(R.id.txt_groupid);
txt_groupid = (TextView) findViewById(R.id.txt_groupid);
mProDialog = new ProgressDialog(FaceIdentifyActivity.this);
mProDialog.setCancelable(true);
mProDialog.setTitle("请稍候");
@ -120,7 +117,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
});
mToast = Toast.makeText(FaceIdentifyActivity.this, "", Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
mToast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
txt_groupid.setText(mGroupId);
}
@ -154,9 +151,9 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
@Override
public void onClick(View view) {
if( null == mIdVerifier ){
if (null == mIdVerifier) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
@ -171,8 +168,8 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
case R.id.online_camera:
// 设置相机拍照后照片保存路径
mPictureFile = new File(Environment.getExternalStorageDirectory(),
"picture" + System.currentTimeMillis()/1000 + ".jpg");
mPictureFile = new File(getExternalFilesDir("msc").getAbsolutePath(),
"picture" + System.currentTimeMillis() / 1000 + ".jpg");
// 启动拍照,并保存到临时文件
Intent mIntent = new Intent();
mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
@ -196,7 +193,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
// 子业务执行参数若无可以传空字符传
StringBuffer params = new StringBuffer();
params.append(",group_id=" + mGroupId +",topc=3");
params.append(",group_id=" + mGroupId + ",topc=3");
// 向子业务写入数据人脸数据可以一次写入
mIdVerifier.writeData("ifr", params.toString(), mImageData, 0, mImageData.length);
// 写入完毕
@ -218,15 +215,13 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
try {
String resultStr = result.getResultString();
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.putExtra("result", resultStr);
startActivity(intent);
this.finish();
}
else {
} else {
showTip("鉴别失败!");
}
} catch (JSONException e) {
@ -241,7 +236,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
}
String fileSrc = null;
if (requestCode == REQUEST_PICTURE_CHOOSE ) {
if (requestCode == REQUEST_PICTURE_CHOOSE) {
if ("file".equals(data.getData().getScheme())) {
// 有些低版本机型返回的Uri模式为file
fileSrc = data.getData().getPath();
@ -256,7 +251,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
cursor.close();
}
// 跳转到图片裁剪页面
cropPicture(this,Uri.fromFile(new File(fileSrc)));
cropPicture(this, Uri.fromFile(new File(fileSrc)));
} else if (requestCode == REQUEST_CAMERA_IMAGE) {
if (null == mPictureFile) {
showTip("拍照失败,请重试");
@ -266,7 +261,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
fileSrc = mPictureFile.getAbsolutePath();
updateGallery(fileSrc);
// 跳转到图片裁剪页面
cropPicture(this,Uri.fromFile(new File(fileSrc)));
cropPicture(this, Uri.fromFile(new File(fileSrc)));
} else if (requestCode == REQUEST_INTENT_CROP) {
// 获取返回数据
@ -276,7 +271,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
fileSrc = getImagePath();
// 若返回数据不为null保存至本地防止裁剪时未能正常保存
if(null != bmp){
if (null != bmp) {
saveBitmapToFile(bmp);
}
@ -293,7 +288,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
mImageBitmap = BitmapFactory.decodeFile(fileSrc, options);
// 若mImageBitmap为空则图片信息不能正常获取
if(null == mImageBitmap) {
if (null == mImageBitmap) {
showTip("图片信息无法正常获取!");
return;
}
@ -365,7 +360,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
}
private void updateGallery(String filename) {
MediaScannerConnection.scanFile(this, new String[] {filename}, null,
MediaScannerConnection.scanFile(this, new String[]{filename}, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
@ -394,6 +389,7 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
/**
* Toast弹出提示
*
* @param str
*/
private void showTip(final String str) {
@ -426,27 +422,25 @@ public class FaceIdentifyActivity extends Activity implements OnClickListener {
/**
* 设置保存图片路径
*
* @return
*/
private String getImagePath(){
String path;
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
return null;
}
path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/MFVDemo/";
private String getImagePath() {
String path = getExternalFilesDir("msc_face").getAbsolutePath() + "/MFVDemo";
File folder = new File(path);
if (folder != null && !folder.exists()) {
if (!folder.exists()) {
folder.mkdirs();
}
path += "mfvtest.jpg";
path += "/mfvtest.jpg";
return path;
}
/**
* 保存Bitmap至本地
*
* @param bmp
*/
private void saveBitmapToFile(Bitmap bmp){
private void saveBitmapToFile(Bitmap bmp) {
String file_path = getImagePath();
File file = new File(file_path);
FileOutputStream fOut;

View File

@ -41,16 +41,16 @@ import java.util.Map;
/**
* 声纹密码和人脸识别相关组操作
* 支持组创建/添加成员/查询组成员/删除成员/删除组/
*
* @author hjyu
* @date 2017/9/28.
* @see this#createGroup()
* @see this#joinGroup(String)
* @see //this#queryGroups()
* @see this#deleteGroup(String, boolean) ,第二个参数用于标示删除组成员or组
*
* @author hjyu
* @date 2017/9/28.
* @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 {
private final static String TAG = GroupManagerActivity.class.getSimpleName();
// 身份验证对象
private IdentityVerifier mIdVerifier;
@ -64,7 +64,7 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
private ProgressDialog mProDialog;
String authId;
String mfv_type;
ArrayList<Map<String,String>> mList;
ArrayList<Map<String, String>> mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -135,15 +135,15 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
list.setDivider(null);
// 添加并且显示
adapter = new MyAdapter(this, mList );
adapter = new MyAdapter(this, mList);
list.setAdapter(adapter);
}
@Override
public void onClick(View v) {
if( null == mIdVerifier ){
if (null == mIdVerifier) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
@ -168,14 +168,10 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent init = new Intent();
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"));
if (mfv_type.equals("ivp")) {
init.setClass(GroupManagerActivity.this,VocalIdentifyActivity.class);
}else {
init.setClass(GroupManagerActivity.this,FaceIdentifyActivity.class);
}
init.putExtra("group_id", map.get("group_id"));
init.setClass(GroupManagerActivity.this, FaceIdentifyActivity.class);
startActivity(init);
}
@ -324,12 +320,12 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
// 设置模型参数若无可以传空字符传
StringBuffer params2 = new StringBuffer();
if(deleteGroup) {
if (deleteGroup) {
params2.append("scope=group");
} else {
// 删除组中指定auth_id用户
params2.append("scope=person");
params2.append(",auth_id="+authId);
params2.append(",auth_id=" + authId);
}
params2.append(",group_id=" + groupId);
// 执行模型操作
@ -378,17 +374,17 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
try {
JSONObject resObj = new JSONObject(result.getResultString());
// 保存到用户信息中用来显示用户加人的组
Map<String,String> map = new HashMap<>();
map.put("group_name",resObj.getString("group_name"));
map.put("group_id",resObj.getString("group_id"));
Map<String, String> map = new HashMap<>();
map.put("group_name", resObj.getString("group_name"));
map.put("group_id", resObj.getString("group_id"));
synchronized (mList) {
if (mList != null && mList.size() >0) {
for(int i = 0;i<mList.size();i++) {
if(!mList.contains(map)) {
if (mList != null && mList.size() > 0) {
for (int i = 0; i < mList.size(); i++) {
if (!mList.contains(map)) {
mList.add(map);
}
}
}else {
} else {
mList.add(map);
}
mList.notify();
@ -421,10 +417,12 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
showTip("查询成功");
stopProgress();
}
@Override
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
}
@Override
public void onError(SpeechError error) {
Log.d(TAG, error.getPlainDescription(true));
@ -439,20 +437,20 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
Log.d(TAG, result.getResultString());
try {
JSONObject resObj = new JSONObject(result.getResultString());
Log.d(TAG,"resObj == "+resObj.toString());
Log.d(TAG, "resObj == " + resObj.toString());
int ret = resObj.getInt("ret");
if(0 != ret) {
if (0 != ret) {
onError(new SpeechError(ret));
return;
} else {
if(result.getResultString().contains("user")) {
if (result.getResultString().contains("user")) {
String user = resObj.getString("user");
showTip("删除组成员"+user+"成功");
showTip("删除组成员" + user + "成功");
} else {
showTip("删除组成功");
// 保存到用户信息中用来显示用户加人的组
for (Map<String,String> map1:mList){
if (map1.get("group_id").equals(resObj.getString("group_id"))){
for (Map<String, String> map1 : mList) {
if (map1.get("group_id").equals(resObj.getString("group_id"))) {
mList.remove(map1);
}
}
@ -488,9 +486,9 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
private Context context;
private LayoutInflater inflater;
public ArrayList<Map<String,String>> arr;
public ArrayList<Map<String, String>> arr;
public MyAdapter(Context context, ArrayList<Map<String,String>> array) {
public MyAdapter(Context context, ArrayList<Map<String, String>> array) {
super();
this.context = context;
inflater = LayoutInflater.from(context);
@ -518,7 +516,7 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
return arg0;
}
public void setArray(ArrayList<Map<String,String>> list) {
public void setArray(ArrayList<Map<String, String>> list) {
this.arr = list;
}
@ -528,8 +526,8 @@ public class GroupManagerActivity extends Activity implements OnClickListener ,A
view = inflater.inflate(R.layout.item_group, null);
}
final TextView edit = (TextView) view.findViewById(R.id.group_item_content);
Map<String,String> map2 = arr.get(arr.size() - position - 1);
edit.setText(map2.get("group_id")+"("+map2.get("group_name")+")"); // 在重构adapter的时候不至于数据错乱
Map<String, String> map2 = arr.get(arr.size() - position - 1);
edit.setText(map2.get("group_id") + "(" + map2.get("group_name") + ")"); // 在重构adapter的时候不至于数据错乱
return view;
}
}

View File

@ -22,6 +22,7 @@ import java.text.DecimalFormat;
/**
* 1:N检测结果解析界面
*
* @author hjyu
* @date 2017/9/28.
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
@ -65,7 +66,7 @@ public class ResultIdentifyActivity extends Activity implements OnClickListener
try {
JSONObject obj = new JSONObject(result);
// 组名称
((TextView)findViewById(R.id.txt_group_name)).setText(obj.getString("group_name"));
((TextView) findViewById(R.id.txt_group_name)).setText(obj.getString("group_name"));
JSONObject ifv_result = obj.getJSONObject("ifv_result");
candidates = ifv_result.getJSONArray("candidates");
@ -143,8 +144,8 @@ public class ResultIdentifyActivity extends Activity implements OnClickListener
}
private String getChineseNumber(int number) {
String[] str = { "", "", "", "", "", "", "", "", "", "" };
String ss[] = new String[] { "", "", "", "", "", "", "", "", "亿" };
String[] str = {"", "", "", "", "", "", "", "", "", ""};
String ss[] = new String[]{"", "", "", "", "", "", "", "", "亿"};
String s = String.valueOf(number);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {

View File

@ -1,31 +1,30 @@
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.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
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
*/
@ -36,7 +35,7 @@ public class IseDemo extends Activity implements OnClickListener {
private final static int REQUEST_CODE_SETTINGS = 1;
private EditText mEvaTextEditText;
private EditText mResultEditText;
private TextView mResultEditText;
private Button mIseStartButton;
private Toast mToast;
@ -62,7 +61,7 @@ public class IseDemo extends Activity implements OnClickListener {
StringBuilder builder = new StringBuilder();
builder.append(result.getResultString());
if(!TextUtils.isEmpty(builder)) {
if (!TextUtils.isEmpty(builder)) {
mResultEditText.setText(builder.toString());
}
mIseStartButton.setEnabled(true);
@ -75,8 +74,8 @@ public class IseDemo extends Activity implements OnClickListener {
@Override
public void onError(SpeechError error) {
mIseStartButton.setEnabled(true);
if(error != null) {
showTip("error:"+ error.getErrorCode() + "," + error.getErrorDescription());
if (error != null) {
showTip("error:" + error.getErrorCode() + "," + error.getErrorDescription());
mResultEditText.setText("");
mResultEditText.setHint("请点击“开始评测”按钮");
} else {
@ -99,7 +98,7 @@ public class IseDemo extends Activity implements OnClickListener {
@Override
public void onVolumeChanged(int volume, byte[] data) {
showTip("当前音量:" + volume);
Log.d(TAG, "返回音频数据:"+data.length);
Log.d(TAG, "返回音频数据:" + data.length);
}
@Override
@ -127,7 +126,7 @@ public class IseDemo extends Activity implements OnClickListener {
private void initUI() {
findViewById(R.id.image_ise_set).setOnClickListener(IseDemo.this);
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.setOnClickListener(IseDemo.this);
findViewById(R.id.ise_parse).setOnClickListener(IseDemo.this);
@ -139,9 +138,9 @@ public class IseDemo extends Activity implements OnClickListener {
@Override
public void onClick(View view) {
if( null == mIse ){
if (null == mIse) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
this.showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
@ -186,6 +185,16 @@ public class IseDemo extends Activity implements OnClickListener {
case R.id.ise_parse:
// 解析最终结果
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();
Result result = resultParser.parse(mLastResult);
@ -240,19 +249,51 @@ public class IseDemo extends Activity implements OnClickListener {
String text = "";
if ("en_us".equals(language)) {
if ("read_word".equals(category)) {
switch (category) {
case "read_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);
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 {
// 中文评测
if ("read_syllable".equals(category)) {
switch (category) {
case "read_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);
} else if ("read_sentence".equals(category)) {
break;
case "read_sentence":
text = getString(R.string.text_cn_sentence);
break;
case "read_chapter":
text = getString(R.string.text_cn_chapter);
break;
}
}
@ -263,12 +304,15 @@ public class IseDemo extends Activity implements OnClickListener {
}
private void showTip(String str) {
if(!TextUtils.isEmpty(str)) {
if (!TextUtils.isEmpty(str)) {
mToast.cancel();
mToast.setText(str);
mToast.show();
}
}
private void setParams() {
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
// 设置评测语言
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");
// 设置流式版本所需参数 : 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.ISE_CATEGORY, category);
mIse.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
@ -290,27 +349,13 @@ public class IseDemo extends Activity implements OnClickListener {
mIse.setParameter(SpeechConstant.VAD_EOS, vad_eos);
mIse.setParameter(SpeechConstant.KEY_SPEECH_TIMEOUT, speech_timeout);
mIse.setParameter(SpeechConstant.RESULT_LEVEL, result_level);
mIse.setParameter(SpeechConstant.AUDIO_FORMAT_AUE,"opus");
// 设置音频保存路径保存音频格式支持pcmwav设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
mIse.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
mIse.setParameter(SpeechConstant.ISE_AUDIO_PATH, Environment.getExternalStorageDirectory().getAbsolutePath() + "/msc/ise.wav");
mIse.setParameter(SpeechConstant.AUDIO_FORMAT_AUE, "opus");
// 设置音频保存路径保存音频格式支持pcmwav
mIse.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
mIse.setParameter(SpeechConstant.ISE_AUDIO_PATH,
getExternalFilesDir("msc").getAbsolutePath() + "/ise.wav");
//通过writeaudio方式直接写入音频时才需要此设置
//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();
}
}

View File

@ -1,189 +1,75 @@
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.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
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.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
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) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
edit_text = (TextView) findViewById(R.id.edit_text);
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);
initView();
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
public void onClick(View view) {
int tag = Integer.parseInt(view.getTag().toString());
Intent intent = null;
switch (tag) {
case 0:
private void initView() {
TextView tipTv = (TextView) findViewById(R.id.tip);
String buf = "当前APPID为" +
getString(R.string.app_id) + "\n" +
getString(R.string.example_explain);
tipTv.setText(buf);
// 语音转写
intent = new Intent(MainActivity.this, IatDemo.class);
break;
case 1:
findViewById(R.id.iatBtn).setOnClickListener(v -> {
startActivity(new Intent(MainActivity.this, IatDemo.class));
});
// 语法识别
intent = new Intent(MainActivity.this, AsrDemo.class);
break;
case 2:
findViewById(R.id.asrBtn).setOnClickListener(v -> {
startActivity(new Intent(MainActivity.this, AsrDemo.class));
});
// 语义理解
findViewById(R.id.nlpBtn).setOnClickListener(v -> {
showTip("请登录http://www.xfyun.cn/ 下载aiui体验吧");
break;
case 3:
});
// 语音合成
intent = new Intent(MainActivity.this, TtsDemo.class);
break;
case 4:
findViewById(R.id.ttsBtn).setOnClickListener(v -> {
startActivity(new Intent(MainActivity.this, TtsDemo.class));
});
// 语音评测
intent = new Intent(MainActivity.this, IseDemo.class);
break;
case 5:
// 唤醒
showTip("请登录http://www.xfyun.cn/ 下载体验吧!");
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);
findViewById(R.id.iseBtn).setOnClickListener(v -> {
startActivity(new Intent(MainActivity.this, IseDemo.class));
});
// 人脸识别
findViewById(R.id.faceBtn).setOnClickListener(v -> {
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) {
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 Toast mToast;
private void showTip(final String str) {
mToast.setText(str);
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT);
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 {
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[] {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION},0x0010);
}
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA
}, 0x0010);
}
} catch (Exception e) {
e.printStackTrace();
@ -195,58 +81,4 @@ public class MainActivity extends Activity implements OnClickListener {
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");
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.iflytek.voicedemo;
import android.app.Application;
import com.iflytek.cloud.Setting;
import com.iflytek.cloud.SpeechUtility;
@ -19,7 +20,7 @@ public class SpeechApp extends Application {
SpeechUtility.createUtility(SpeechApp.this, "appid=" + getString(R.string.app_id));
// 以下语句用于设置日志开关默认开启设置成false时关闭语音云SDK日志打印
// Setting.setShowLog(false);
Setting.setShowLog(true);
super.onCreate();
}

View File

@ -1,6 +1,5 @@
package com.iflytek.voicedemo;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
@ -8,8 +7,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.MemoryFile;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.BackgroundColorSpan;
@ -29,15 +26,11 @@ import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechEvent;
import com.iflytek.cloud.SpeechSynthesizer;
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 java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
import java.io.RandomAccessFile;
public class TtsDemo extends Activity implements OnClickListener {
@ -49,8 +42,8 @@ public class TtsDemo extends Activity implements OnClickListener {
private String voicer = "xiaoyan";
private String[] mCloudVoicersEntries;
private String[] mCloudVoicersValue ;
String texts = "";
private String[] mCloudVoicersValue;
private String texts = "";
// 缓冲进度
private int mPercentForBuffering = 0;
@ -64,30 +57,20 @@ public class TtsDemo extends Activity implements OnClickListener {
private Toast mToast;
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) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.ttsdemo);
texts = getResources().getString(R.string.text_tts_source);
initLayout();
DebugLog.setShowLog(true);
// 初始化合成对象
mTts = SpeechSynthesizer.createSynthesizer(TtsDemo.this, mTtsInitListener);
// 云端发音人名称列表
mCloudVoicersEntries = getResources().getStringArray(R.array.voicer_cloud_entries);
mCloudVoicersValue = getResources().getStringArray(R.array.voicer_cloud_values);
mSharedPreferences = getSharedPreferences(TtsSettings.PREFER_NAME, MODE_PRIVATE);
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
}
/**
@ -101,7 +84,7 @@ public class TtsDemo extends Activity implements OnClickListener {
findViewById(R.id.image_tts_set).setOnClickListener(TtsDemo.this);
findViewById(R.id.tts_btn_person_select).setOnClickListener(TtsDemo.this);
mRadioGroup=((RadioGroup) findViewById(R.id.tts_rediogroup));
mRadioGroup = ((RadioGroup) findViewById(R.id.tts_rediogroup));
mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
@ -115,23 +98,23 @@ public class TtsDemo extends Activity implements OnClickListener {
}
}
} );
});
}
@Override
public void onClick(View view) {
if( null == mTts ){
if (null == mTts) {
// 创建单例失败 21001 错误为同样原因参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
this.showTip("创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化");
return;
}
switch(view.getId()) {
switch (view.getId()) {
case R.id.image_tts_set:
if(SpeechConstant.TYPE_CLOUD.equals(mEngineType)){
if (SpeechConstant.TYPE_CLOUD.equals(mEngineType)) {
Intent intent = new Intent(TtsDemo.this, TtsSettings.class);
startActivity(intent);
}else{
} else {
showTip("请前往xfyun.cn下载离线合成体验");
}
break;
@ -139,22 +122,23 @@ public class TtsDemo extends Activity implements OnClickListener {
// 收到onCompleted 回调时合成结束生成合成音频
// 合成的音频格式只支持pcm格式
case R.id.tts_play:
// 移动数据分析收集开始合成事件
/*FlowerCollector.onEvent(TtsDemo.this, "tts_play");*/
pcmFile = new File(getExternalCacheDir().getAbsolutePath(), "tts_pcmFile.pcm");
pcmFile.delete();
texts = ((EditText) findViewById(R.id.tts_text)).getText().toString();
// 设置参数
setParam();
// 合成并播放
int code = mTts.startSpeaking(texts, mTtsListener);
// /**
// * 只保存音频不进行播放接口,调用此接口请注释startSpeaking接口
// * text:要合成的文本uri:需要保存的音频全路径listener:回调接口
// */
String path = Environment.getExternalStorageDirectory()+"/tts.pcm";
// int code = mTts.synthesizeToUri(texts, path, mTtsListener);
// String path = getExternalFilesDir("msc").getAbsolutePath() + "/tts.pcm";
// // synthesizeToUri 只保存音频不进行播放
// int code = mTts.synthesizeToUri(texts, path, mTtsListener);
if (code != ErrorCode.SUCCESS) {
showTip("语音合成失败,错误码: " + code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("语音合成失败,错误码: " + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
break;
// 取消合成
@ -171,15 +155,17 @@ public class TtsDemo extends Activity implements OnClickListener {
break;
// 选择发音人
case R.id.tts_btn_person_select:
showPresonSelectDialog();
showPersonSelectDialog();
break;
}
}
private int selectedNum = 0;
/**
* 发音人选择
*/
private void showPresonSelectDialog() {
private void showPersonSelectDialog() {
switch (mRadioGroup.getCheckedRadioButtonId()) {
// 选择在线合成
case R.id.tts_radioCloud:
@ -192,7 +178,7 @@ public class TtsDemo extends Activity implements OnClickListener {
voicer = mCloudVoicersValue[which];
if ("catherine".equals(voicer) || "henry".equals(voicer) || "vimary".equals(voicer)) {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source_en);
}else {
} else {
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source);
}
selectedNum = which;
@ -214,7 +200,7 @@ public class TtsDemo extends Activity implements OnClickListener {
public void onInit(int code) {
Log.d(TAG, "InitListener init() code = " + code);
if (code != ErrorCode.SUCCESS) {
showTip("初始化失败,错误码:"+code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("初始化失败,错误码:" + code + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
} else {
// 初始化成功之后可以调用startSpeaking方法
// 有的开发者在onCreate方法中创建完合成对象之后马上就调用startSpeaking进行合成
@ -261,30 +247,18 @@ public class TtsDemo extends Activity implements OnClickListener {
showTip(String.format(getString(R.string.tts_toast_format),
mPercentForBuffering, mPercentForPlaying));
SpannableStringBuilder style=new SpannableStringBuilder(texts);
Log.e(TAG,"beginPos = "+beginPos +" endPos = "+endPos);
style.setSpan(new BackgroundColorSpan(Color.RED),beginPos,endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableStringBuilder style = new SpannableStringBuilder(texts);
Log.e(TAG, "beginPos = " + beginPos + " endPos = " + endPos);
style.setSpan(new BackgroundColorSpan(Color.RED), beginPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((EditText) findViewById(R.id.tts_text)).setText(style);
}
@Override
public void onCompleted(SpeechError error) {
System.out.println("oncompleted");
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("播放完成");
if (error != null) {
showTip(error.getPlainDescription(true));
return;
}
}
@ -296,33 +270,39 @@ public class TtsDemo extends Activity implements OnClickListener {
String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
Log.d(TAG, "session id =" + sid);
}
//当设置SpeechConstant.TTS_DATA_NOTIFY为1时抛出buf数据
// 当设置 SpeechConstant.TTS_DATA_NOTIFY 为1时抛出buf数据
if (SpeechEvent.EVENT_TTS_BUFFER == eventType) {
byte[] buf = obj.getByteArray(SpeechEvent.KEY_EVENT_TTS_BUFFER);
Log.e("MscSpeechLog_", "bufis =" + buf.length);
container.add(buf);
Log.e(TAG, "EVENT_TTS_BUFFER = " + buf.length);
// 保存文件
appendFile(pcmFile, buf);
}
}
};
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
*/
private void setParam(){
private void setParam() {
// 清空参数
mTts.setParameter(SpeechConstant.PARAMS, null);
// 根据合成引擎设置相应参数
if(mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
if (mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
//支持实时音频返回仅在synthesizeToUri条件下支持
// 支持实时音频返回仅在 synthesizeToUri 条件下支持
mTts.setParameter(SpeechConstant.TTS_DATA_NOTIFY, "1");
// mTts.setParameter(SpeechConstant.TTS_BUFFER_TIME,"1");
@ -334,7 +314,7 @@ public class TtsDemo extends Activity implements OnClickListener {
mTts.setParameter(SpeechConstant.PITCH, mSharedPreferences.getString("pitch_preference", "50"));
//设置合成音量
mTts.setParameter(SpeechConstant.VOLUME, mSharedPreferences.getString("volume_preference", "50"));
}else {
} else {
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
mTts.setParameter(SpeechConstant.VOICE_NAME, "");
@ -347,49 +327,35 @@ public class TtsDemo extends Activity implements OnClickListener {
// 设置音频保存路径保存音频格式支持pcmwav设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
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
protected void onDestroy() {
super.onDestroy();
if( null != mTts ){
if (null != mTts) {
mTts.stopSpeaking();
// 退出时释放连接
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)
return;
/**
* 给file追加数据
*/
private void appendFile(File file, byte[] buffer) {
try {
if(memFile == null)
{
Log.e("MscSpeechLog_","ffffffffff");
String mFilepath = Environment.getExternalStorageDirectory()+"/1.pcm";
memFile = new MemoryFile(mFilepath,1920000);
memFile.allowPurging(false);
if (!file.exists()) {
boolean b = file.createNewFile();
}
memFile.writeBytes(data, 0, (int)mTotalSize, data.length);
mTotalSize += data.length;
} finally {
RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
randomFile.seek(file.length());
randomFile.write(buffer);
randomFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}

View File

@ -5,13 +5,12 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
@ -19,7 +18,6 @@ import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.iflytek.cloud.ErrorCode;
@ -29,11 +27,9 @@ import com.iflytek.cloud.IdentityVerifier;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechUtility;
import com.iflytek.speech.util.FaceUtil;
import com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity;
import com.iflytek.voicedemo.R;
import com.iflytek.voicedemo.vocalverify.VocalVerifyDemo;
import org.json.JSONException;
import org.json.JSONObject;
@ -42,18 +38,14 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
/**
*
* 此demo意在为提供在线人脸识别相关api调用方式1:1 识别
*
* @author hjyu
* @date 2017/9/28.
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
*/
public class OnlineFaceDemo extends Activity implements View.OnClickListener {
private final String TAG = "OnlineFaceDemo";
private final int REQUEST_PICTURE_CHOOSE = 1;
private final int REQUEST_CAMERA_IMAGE = 2;
private Bitmap mImage = null;
private byte[] mImageData = null;
@ -112,7 +104,7 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
if (ErrorCode.SUCCESS == errorCode) {
showTip("引擎初始化成功");
} else {
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
showTip("引擎初始化失败,错误码:" + errorCode + ",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
}
}
});
@ -149,8 +141,6 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
}
/**
* 人脸注册监听器
*/
@ -170,7 +160,7 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
if (ErrorCode.SUCCESS == ret) {
showTip("注册成功");
}else {
} else {
showTip(new SpeechError(ret).getPlainDescription(true));
}
} catch (JSONException e) {
@ -208,7 +198,7 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
try {
JSONObject object = new JSONObject(result.getResultString());
Log.d(TAG,"object is: "+object.toString());
Log.d(TAG, "object is: " + object.toString());
String decision = object.getString("decision");
if ("accepted".equalsIgnoreCase(decision)) {
@ -281,7 +271,6 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
};
private void executeModelCommand(String cmd) {
// 设置模型参数若无可以传空字符传
StringBuffer params = new StringBuffer();
@ -293,10 +282,10 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
public void onClick(View view) {
int ret = ErrorCode.SUCCESS;
mAuthid = online_authid.getText().toString();
if(TextUtils.isEmpty(mAuthid)) {
if (TextUtils.isEmpty(mAuthid)) {
showTip("请输入用户ID");
return;
}else {
} else {
online_authid.setEnabled(false);
}
@ -305,7 +294,7 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
startActivityForResult(intent, FaceUtil.REQUEST_PICTURE_CHOOSE);
break;
case R.id.online_reg:
if (TextUtils.isEmpty(mAuthid)) {
@ -376,15 +365,8 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
break;
case R.id.online_camera:
// 设置相机拍照后照片保存路径
mPictureFile = new File(Environment.getExternalStorageDirectory(),
"picture" + System.currentTimeMillis()/1000 + ".jpg");
// 启动拍照,并保存到临时文件
Intent mIntent = new Intent();
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);
takePhoto();
break;
case R.id.btn_modle_delete:
// 人脸模型删除
@ -393,60 +375,59 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
break;
case R.id.btn_identity:
Intent init = new Intent(OnlineFaceDemo.this, GroupManagerActivity.class);
init.putExtra("auth_id",mAuthid);
init.putExtra("mfv_scenes","ifr");
init.putExtra("auth_id", mAuthid);
init.putExtra("mfv_scenes", "ifr");
startActivity(init);
break;
default:
break;
}//end of switch
if( ErrorCode.SUCCESS != ret ){
if (ErrorCode.SUCCESS != ret) {
mProDialog.dismiss();
showTip( "出现错误:"+ret );
showTip("出现错误:" + ret);
}
}
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
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
String fileSrc = null;
if (requestCode == REQUEST_PICTURE_CHOOSE) {
if ("file".equals(data.getData().getScheme())) {
// 有些低版本机型返回的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();
}
// 选择文件
if (requestCode == FaceUtil.REQUEST_PICTURE_CHOOSE) {
// 跳转到图片裁剪页面
FaceUtil.cropPicture(this,Uri.fromFile(new File(fileSrc)));
} else if (requestCode == REQUEST_CAMERA_IMAGE) {
if (null == mPictureFile) {
FaceUtil.cropPicture(this, data.getData());
return;
}
// 拍照
if (requestCode == FaceUtil.REQUEST_CAMERA_IMAGE) {
if (null == mPictureFile || !mPictureFile.exists()) {
showTip("拍照失败,请重试");
return;
}
fileSrc = mPictureFile.getAbsolutePath();
updateGallery(fileSrc);
// 跳转到图片裁剪页面
FaceUtil.cropPicture(this,Uri.fromFile(new File(fileSrc)));
} else if (requestCode == FaceUtil.REQUEST_CROP_IMAGE) {
// 获取返回数据
Bitmap bmp = data.getParcelableExtra("data");
// 若返回数据不为null保存至本地防止裁剪时未能正常保存
if(null != bmp){
FaceUtil.saveBitmapToFile(OnlineFaceDemo.this, bmp);
FaceUtil.cropPicture(
OnlineFaceDemo.this,
FaceUtil.parseUri(getApplication(), mPictureFile));
return;
}
// 裁剪
if (requestCode == FaceUtil.REQUEST_CROP_IMAGE) {
// 获取图片保存路径
fileSrc = FaceUtil.getImagePath(OnlineFaceDemo.this);
// 获取图片的宽和高
@ -461,29 +442,23 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
options.inJustDecodeBounds = false;
mImage = BitmapFactory.decodeFile(fileSrc, options);
// 若mImageBitmap为空则图片信息不能正常获取
if(null == mImage) {
if (null == mImage) {
showTip("图片信息无法正常获取!");
return;
}
// 部分手机会对图片做旋转这里检测旋转角度
int degree = FaceUtil.readPictureDegree(fileSrc);
if (degree != 0) {
// 把图片旋转为正的方向
mImage = FaceUtil.rotateImage(degree, mImage);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//可根据流量及网络状况对图片进行压缩
mImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);
mImageData = baos.toByteArray();
((ImageView) findViewById(R.id.online_img)).setImageBitmap(mImage);
}
}
@Override
@ -495,9 +470,8 @@ public class OnlineFaceDemo extends Activity implements View.OnClickListener {
}
private void updateGallery(String filename) {
MediaScannerConnection.scanFile(this, new String[] {filename}, null,
MediaScannerConnection.scanFile(this, new String[]{filename}, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/list_backgroud_color"></item>
<item android:drawable="@drawable/layout_backgroud"></item>
</selector>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/setting" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/setting_p" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/setting_p" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/setting" android:state_focused="true" android:state_pressed="false" />
<item android:drawable="@drawable/setting_p" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@drawable/setting_p" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@drawable/setting"></item>
</selector>

View File

@ -6,7 +6,7 @@
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dp" >
android:padding="10dp">
<TextView
android:layout_width="match_parent"
@ -21,7 +21,7 @@
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:gravity="center" >
android:gravity="center">
<ImageView
android:id="@+id/online_img"
@ -36,9 +36,7 @@
android:layout_height="wrap_content"
android:id="@+id/txt_groupid"
android:layout_gravity="center_horizontal"
android:padding="5dp"/>
android:padding="5dp" />
<LinearLayout
@ -46,7 +44,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/online_pick"
@ -71,7 +69,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/btn_identity"

View File

@ -1,8 +1,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/group_manager_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_my_group"

View File

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
android:orientation="vertical">
<!-- 标题栏 -->
<RelativeLayout
@ -19,14 +19,14 @@
android:layout_height="30dp"
android:gravity="center"
android:textSize="26sp"
android:text="1:N验证结果"/>
android:text="1:N验证结果" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/idf_result_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:orientation="vertical">
<LinearLayout
android:id="@+id/lly_group_name"
@ -35,7 +35,7 @@
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="30dp"
android:orientation="horizontal" >
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
@ -74,8 +74,7 @@
android:layout_alignLeft="@id/txt_hint"
android:fadingEdge="none"
android:cacheColorHint="#00000000"
android:listSelector="#00000000" >
</ListView>
android:listSelector="#00000000"></ListView>
</RelativeLayout>
</LinearLayout>

View File

@ -1,5 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/group_manager_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -10,7 +9,7 @@
android:id="@+id/rllyt_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical" >
android:gravity="center_vertical">
<TextView
android:id="@+id/txt_login_title"
@ -29,7 +28,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:gravity="center" >
android:gravity="center">
<ImageView
android:layout_width="17dp"
@ -53,7 +52,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/user_info_layout"
android:layout_marginTop="25dp"
android:paddingBottom="10dp" >
android:paddingBottom="10dp">
<View
android:id="@+id/line_create"
@ -70,7 +69,7 @@
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:visibility="visible" >
android:visibility="visible">
<EditText
android:id="@+id/edt_group_name"
@ -82,8 +81,7 @@
android:hint="请输入组名用于创建组..."
android:inputType="text"
android:paddingLeft="5dp"
android:textSize="18sp" >
</EditText>
android:textSize="18sp"></EditText>
</LinearLayout>

View File

@ -7,12 +7,12 @@
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
@ -35,29 +35,29 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="@string/text_show_iat_result"
android:gravity="top|left"
android:hint="@string/text_show_iat_result"
android:paddingBottom="10dp"
android:textSize="20sp" />
<EditText
android:id="@+id/iat_contacts"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="@string/text_show_contacts"
android:gravity="top|left"
android:hint="@string/text_show_contacts"
android:paddingBottom="10dp"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="2dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/iat_recognize"
@ -89,13 +89,12 @@
android:id="@+id/languageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击设置小语种,当前语种:中文(普通话)"
android:layout_marginTop="10dp"
android:textSize="20sp"
android:gravity="center_horizontal"
android:clickable="true"
android:focusable="true"
/>
android:gravity="center_horizontal"
android:text="点击设置小语种,当前语种:中文(普通话)"
android:textSize="20sp" />
<Button
android:id="@+id/iat_recognize_stream"
@ -109,32 +108,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="上传联系人、词表,可以使云端识别联系人和词表更加准确,这里上传的内容对语义理解同样有效。"
android:text="上传词表,可以使云端识别更加准确,这里上传的内容对语义理解同样有效。"
android:textSize="@dimen/txt_size" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/iat_upload_contacts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="上传联系人"
android:textSize="17sp" />
<Button
android:id="@+id/iat_upload_userwords"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginBottom="4dp"
android:text="上传词表"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<ImageView
android:id="@+id/ifly_mnotice_image_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
</RelativeLayout>

View File

@ -5,12 +5,12 @@
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
@ -28,32 +28,44 @@
android:background="@drawable/main_setting_btn_np" />
</RelativeLayout>
<EditText
android:id="@+id/ise_eva_text"
<ScrollView
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginBottom="5dp"
android:gravity="top|left"
android:textSize="20sp" />
<EditText
android:id="@+id/ise_result_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:editable="false"
android:gravity="top|left"
android:hint="请点击“开始评测”按钮"
android:textSize="16sp" />
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/ise_eva_text"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_marginBottom="5dp"
android:gravity="top|left"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="2dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/ise_start"
@ -75,10 +87,10 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="2dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/ise_cancel"

View File

@ -7,18 +7,19 @@
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="讯飞语法示例"
android:textColor="@color/black"
android:textSize="30sp" />
</RelativeLayout>
@ -36,7 +37,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/isr_grammar"
@ -54,7 +55,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/isr_recognize"
@ -71,7 +72,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/isr_stop"

View File

@ -5,13 +5,13 @@
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center" >
android:gravity="center">
<TextView
android:layout_width="0dp"
@ -27,7 +27,7 @@
android:layout_height="wrap_content"
android:id="@+id/set_authId"
android:maxLines="1"
android:hint="请输入 authId"/>
android:hint="请输入 authId" />
<EditText
android:id="@+id/edt_result"
@ -43,7 +43,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/isv_getpassword"
@ -78,14 +78,14 @@
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal" >
android:orientation="horizontal">
<RadioGroup
android:id="@+id/vocal_radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
android:weightSum="2">
<RadioButton
android:id="@+id/vocal_radioEnroll"
@ -93,8 +93,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 声纹注册"
android:textSize="18sp" >
</RadioButton>
android:textSize="18sp"></RadioButton>
<RadioButton
android:id="@+id/vocal_radioVerify"
@ -102,8 +101,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 1:1验证"
android:textSize="18sp" >
</RadioButton>
android:textSize="18sp"></RadioButton>
</RadioGroup>
</LinearLayout>
@ -111,7 +109,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/isv_reocrd"

View File

@ -5,7 +5,7 @@
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical"
android:paddingBottom="3dip" >
android:paddingBottom="3dip">
<TextView
android:id="@+id/group_item_content"
@ -13,7 +13,6 @@
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textColor="@color/white"
android:textSize="20sp" >
</TextView>
android:textSize="20sp"></TextView>
</LinearLayout>

View File

@ -6,7 +6,7 @@
android:background="@android:color/transparent"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:paddingBottom="3dip" >
android:paddingBottom="3dip">
<TextView
android:id="@+id/identify_item_number"
@ -15,6 +15,7 @@
android:text="第一:"
android:textColor="#ebf657"
android:textSize="20sp" />
<TextView
android:id="@+id/identify_item_user"
android:layout_width="wrap_content"
@ -23,6 +24,7 @@
android:text="18505511338"
android:textColor="#ebf657"
android:textSize="20sp" />
<TextView
android:id="@+id/identify_item_score"
android:layout_width="wrap_content"

View File

@ -4,15 +4,7 @@
android:layout_height="match_parent"
android:background="@drawable/list_bg_color"
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>

View File

@ -3,28 +3,101 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_backgroud"
android:orientation="vertical" >
android:orientation="vertical">
<include layout="@layout/title" />
<TextView
android:id="@+id/edit_text"
android:id="@+id/tip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_"
android:layout_marginRight="@dimen/margin_"
android:textColor="@color/white"
android:textSize="@dimen/txt_size" />
<ListView
android:id="@+id/listview_main"
<ScrollView
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_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:cacheColorHint="@color/white"
android:divider="@drawable/line_background"
android:dividerHeight="@dimen/line_height"
android:paddingBottom="5dp" />
android:orientation="vertical">
<Button
android:id="@+id/iatBtn"
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/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>

View File

@ -6,7 +6,7 @@
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dp" >
android:padding="10dp">
<TextView
android:layout_width="match_parent"
@ -21,7 +21,7 @@
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:gravity="center" >
android:gravity="center">
<ImageView
android:id="@+id/online_img"
@ -37,7 +37,7 @@
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<EditText
android:id="@+id/online_authid"
@ -46,20 +46,19 @@
android:digits="abcdefghijklmnopqrstuvwxyz0123456789_"
android:hint="请输入 authid"
android:maxLength="18"
android:textSize="16sp" >
android:textSize="16sp">
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/online_pick"
@ -83,7 +82,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/online_reg"
@ -108,7 +107,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/btn_modle_delete"
@ -116,7 +115,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"
android:text="@string/face_model_delete"/>
android:text="@string/face_model_delete" />
<Button
android:id="@+id/btn_identity"

View File

@ -3,13 +3,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="center" >
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="@color/white"
android:text="讯飞语音示例"
android:textSize="30sp" />

View File

@ -7,12 +7,12 @@
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
@ -44,14 +44,14 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
android:orientation="horizontal">
<RadioGroup
android:id="@+id/tts_rediogroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
android:orientation="horizontal">
<RadioButton
android:id="@+id/tts_radioCloud"
@ -77,7 +77,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/tts_play"
@ -102,7 +102,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/tts_pause"

View File

@ -7,12 +7,12 @@
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
@ -46,7 +46,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/text_understander"
@ -71,7 +71,7 @@
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
android:orientation="horizontal">
<Button
android:id="@+id/understander_stop"

View File

@ -8,6 +8,7 @@
<drawable name="line_background">#161823</drawable>
<color name="white">#FFFFFF</color>
<color name="black">#000</color>
<!-- 控件按下时显示的颜色 -->
<color name="list_backgroud_color">#2fb3cb</color>

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="iat_language_preference"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:dialogTitle="请输入语速:在线(0-100)本地(0-200)"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="understander_language_preference"
android:title="语言设置"
@ -29,11 +29,11 @@
android:summary="默认值:有标点 "
android:defaultValue="1" />
<!-- <CheckBoxPreference -->
<!-- android:key="nbest_preference" -->
<!-- android:title="@string/set_multiple_candidate_title" -->
<!-- android:summary="@string/set_multiple_candidate_summary" -->
<!-- android:defaultValue="false" /> -->
<!-- <CheckBoxPreference -->
<!-- android:key="nbest_preference" -->
<!-- android:title="@string/set_multiple_candidate_title" -->
<!-- android:summary="@string/set_multiple_candidate_summary" -->
<!-- android:defaultValue="false" /> -->
</PreferenceScreen>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="url_preference"
@ -11,7 +11,7 @@
<EditTextPreference
android:key="url_edit"
android:title="输入域名(优先级较高) 格式参考:域名(+:端口)"
android:summary=""/>
android:summary="" />
</PreferenceScreen>

Binary file not shown.