Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f46962da29 | ||
![]() |
29cd7f690d | ||
![]() |
368be1351b | ||
![]() |
5dccf5eff1 |
42
src/android/sample/speechDemo/build.gradle
Normal file
@ -0,0 +1,42 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '26.0.2'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.iflytek.voicedemo"
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 28
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compile files('libs/Msc.jar')
|
||||
// compile project(':MscLibSrc')
|
||||
compile 'com.android.support:support-v4:23.+'
|
||||
}
|
BIN
src/android/sample/speechDemo/libs/Msc.jar
Normal file
BIN
src/android/sample/speechDemo/libs/arm64-v8a/libmsc.so
Normal file
BIN
src/android/sample/speechDemo/libs/armeabi-v7a/libmsc.so
Normal file
3
src/android/sample/speechDemo/lint.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<lint>
|
||||
</lint>
|
101
src/android/sample/speechDemo/msc.cfg
Normal file
@ -0,0 +1,101 @@
|
||||
## Copyright (C) 2001-2010 iFLYTEK.
|
||||
## Use ';' and '#' character for notation
|
||||
## Note: Commands in this cfg file is case sensitive
|
||||
|
||||
[local]
|
||||
timeout = 15000
|
||||
pre_connect = 0
|
||||
search_best_url = 0
|
||||
upload_info = 1
|
||||
|
||||
[aiui]
|
||||
#aiui_sync_url = http://172.16.154.43:8080/sync/v1/upload.do
|
||||
#aiui_third_url = http://172.16.154.10:8080/sync/v1/syncthird.do
|
||||
#aiui_prs_url = http://172.16.154.17:1289/aiui/prs/app/v1/upload.do
|
||||
#aiui_opsync_url = https://172.16.154.21:443/athena/opsync
|
||||
|
||||
##<23><><EFBFBD><EFBFBD>
|
||||
#aiui_up_url = http://aiui.openspeech.cn:1032/aiui/v1/upload.do
|
||||
#aiui_pushnode_url = http://aiui.openspeech.cn:80/aiui/v1/pushnode.do
|
||||
#aiui_chid_url = https://aiui.openspeech.cn:443/v1.1/server/register
|
||||
##<23><><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
#aiui_up_url = http://172.16.154.43:1032/aiui/v1/upload.do
|
||||
#aiui_pushnode_url = http://172.16.154.43:80/aiui/v1/pushnode.do
|
||||
#aiui_chid_url = http://172.16.154.43:443/v1.1/server/register
|
||||
##aiui<75><69>־
|
||||
#no_sessinfodata = 1
|
||||
sessinfodata = sessinfo.txt
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1>
|
||||
rslt_timeout = 5000
|
||||
##<23><>ȡchid<69><64>ʱ
|
||||
chid_timeout = 3000
|
||||
##<23><>ȡpushnode<64><65>ʱ
|
||||
pushnode_timeout = 3000
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
down_stream_timeout = 20000
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
up_stream_req_timeout = 50000
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>û<EFBFBD><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ڵȴ<DAB5><C8B4><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
up_stream_resp_timeout = 3000
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
heart_beat_timeout = 15000
|
||||
##<><D7BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>֮<EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD>ʹ<EFBFBD>Ѿ<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>Ҳ<EFBFBD><D2B2>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ϊû<CEAA><C3BB><EFBFBD><D7BC><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
||||
ready_delay_timeout = 1
|
||||
##<23><>ȡchid<69>쳣ʱ<ECB3A3><CAB1><EFBFBD><EFBFBD>ʱһ<CAB1><D2BB>ʱ<EFBFBD><CAB1><EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
chid_delay_reset_timeout = 3000
|
||||
##<23><>ȡpushnode<64>쳣ʱ<ECB3A3><CAB1><EFBFBD><EFBFBD>ʱһ<CAB1><D2BB>ʱ<EFBFBD><CAB1><EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
pushnode_delay_reset_timeout = 3000
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>ȡchid<69><64>pushnode<64><65>Ĭ<EFBFBD><C4AC>ֵ42000000<30><30>11Сʱ40<34><30><EFBFBD>ӣ<EFBFBD>
|
||||
reset_chid_pushnode_timeout = 42000000
|
||||
##stmid_q<5F>е<EFBFBD>Ԫ<EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD>ǰ<EFBFBD>濪ʼɾ<CABC><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>stmidͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ20
|
||||
stmid_q_max = 20
|
||||
|
||||
[tts]
|
||||
##<23>ϳ<EFBFBD><CFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>Χ(0, 4096]<5D><>Ĭ<EFBFBD><C4AC>ֵ1024<32><34>
|
||||
max_text_size = 1024
|
||||
##<23><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1>غϳ<D8BA>ʱ<EFBFBD><CAB1>Ч<EFBFBD><D0A7>Ϊÿ<CEAA>η<EFBFBD><CEB7>ص<EFBFBD><D8B5><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ݴ<EFBFBD>С<EFBFBD><D0A1>
|
||||
buff_size = 8192
|
||||
|
||||
[asr]
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>λByte<74><65><EFBFBD><EFBFBD>Χ(0, 1MB]<5D><>Ĭ<EFBFBD><C4AC>ֵ256KB
|
||||
max_audio_size = 262144
|
||||
##<23><>С<EFBFBD><D0A1>Ƶ<EFBFBD><C6B5><EFBFBD>볤<EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>λByte<74><65><EFBFBD><EFBFBD>Χ(0, max_audio_size]<5D><>Ĭ<EFBFBD><C4AC>ֵ5KB
|
||||
coding_chunk_size = 5120
|
||||
##<23>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>VAD<41><44><EFBFBD>ж˵<D0B6><CBB5><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD><EFBFBD>
|
||||
vad_enable = true
|
||||
##<23><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>㷨<EFBFBD><E3B7A8>ģʽ<C4A3><CABD>audio_coding<6E><67>coding_levelȡֵ<C8A1><D6B5>Χ<EFBFBD><CEA7><EFBFBD>±<EFBFBD><C2B1><EFBFBD>ʾ<EFBFBD><CABE>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD>ֱ<EFBFBD>Ϊspeex-wb<77><62>7<EFBFBD><37>
|
||||
# ----------------------------------
|
||||
# | audio_coding | coding_level |
|
||||
# ----------------------------------
|
||||
# | speex | 0-10 |
|
||||
# | speex-wb | 0-10 |
|
||||
# | raw | <20><>Ч |
|
||||
# ----------------------------------
|
||||
audio_coding = speex-wb
|
||||
coding_level = 7
|
||||
|
||||
[hcr]
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD><C8A3><EFBFBD>λByte<74><65><EFBFBD><EFBFBD>Χ(0, 16KB]<5D><>Ĭ<EFBFBD><C4AC>ֵ8KB
|
||||
max_data_size = 8192
|
||||
|
||||
[isv]
|
||||
##<23><><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>λByte<74><65><EFBFBD><EFBFBD>Χ(0, 2MB]<5D><>Ĭ<EFBFBD><C4AC>ֵ512KB
|
||||
max_audio_size = 524288
|
||||
##<23><>С<EFBFBD><D0A1>Ƶ<EFBFBD><C6B5><EFBFBD>볤<EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>λByte<74><65><EFBFBD><EFBFBD>Χ(0, max_audio_size]<5D><>Ĭ<EFBFBD><C4AC>ֵ5KB
|
||||
coding_chunk_size = 5120
|
||||
##<23><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>㷨<EFBFBD><E3B7A8>ģʽ<C4A3><CABD>audio_coding<6E><67>coding_levelȡֵ<C8A1><D6B5>Χ<EFBFBD><CEA7><EFBFBD>Բο<D4B2>asr<73><72>
|
||||
audio_coding = speex-wb
|
||||
coding_level = 7
|
||||
|
||||
[logger]
|
||||
##<23><><EFBFBD><EFBFBD>û<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>ôMSC<53><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>־<EFBFBD><D6BE>Ϣ
|
||||
file = msc.log
|
||||
title = Mobile Speech Client
|
||||
level = -1
|
||||
output = 1
|
||||
filter = -1
|
||||
style = -1
|
||||
flush = 0
|
||||
maxsize = 104857600
|
||||
overwrite = 1
|
||||
maxfile =
|
96
src/android/sample/speechDemo/speechDemo.iml
Normal file
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":speechDemo" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":speechDemo" />
|
||||
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.0.0" />
|
||||
<option name="LAST_KNOWN_AGP_VERSION" value="3.0.0" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<afterSyncTasks>
|
||||
<task>generateDebugSources</task>
|
||||
</afterSyncTasks>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
|
||||
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:23.4.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-v4:23.4.0@aar" level="project" />
|
||||
<orderEntry type="module" module-name="MscLibSrc" />
|
||||
</component>
|
||||
</module>
|
114
src/android/sample/speechDemo/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.iflytek.voicedemo"
|
||||
android:versionCode="1"
|
||||
android:versionName="2.0.1018.1013" >
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:name="SpeechApp"
|
||||
android:label="讯飞语音示例" >
|
||||
<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" >
|
||||
<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.voicedemo.IatDemo"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.iflytek.voicedemo.AsrDemo"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.iflytek.voicedemo.TtsDemo"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<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>
|
||||
<activity
|
||||
android:name="com.iflytek.voicedemo.faceonline.OnlineFaceDemo"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
<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>
|
||||
<activity
|
||||
android:name="com.iflytek.voicedemo.IdentifyGroup.ResultIdentifyActivity"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.iflytek.speech.setting.IseSettings"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.iflytek.speech.setting.UrlSettings"
|
||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<!-- 移动统计分析 -->
|
||||
<meta-data
|
||||
android:name="IFLYTEK_APPKEY"
|
||||
android:value="'5cee406c'" />
|
||||
<meta-data
|
||||
android:name="IFLYTEK_CHANNEL"
|
||||
android:value="Android_Demo" />
|
||||
|
||||
|
||||
</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>
|
12
src/android/sample/speechDemo/src/main/assets/call.bnf
Normal file
@ -0,0 +1,12 @@
|
||||
#BNF+IAT 1.0 UTF-8;
|
||||
!grammar call;
|
||||
!slot <contact>;
|
||||
!slot <callPre>;
|
||||
!slot <callPhone>;
|
||||
!slot <callTo>;
|
||||
!start <callStart>;
|
||||
<callStart>:[<callPre>][<callTo>]<contact><callPhone>|[<callPre>]<callPhone>[<callTo>]<contact>;
|
||||
<contact>:张海洋;
|
||||
<callPre>:我要|我想|我想要;
|
||||
<callPhone>:打电话;
|
||||
<callTo>:给;
|
@ -0,0 +1,8 @@
|
||||
#ABNF 1.0 UTF-8;
|
||||
language zh-CN;
|
||||
mode voice;
|
||||
|
||||
root $main;
|
||||
$main = $place1 到 $place2;
|
||||
$place1 = 北京|武汉|南京|天津|东京;
|
||||
$place2 = 上海|合肥;
|
BIN
src/android/sample/speechDemo/src/main/assets/iattest.wav
Normal file
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 7.7 KiB |
BIN
src/android/sample/speechDemo/src/main/assets/isetest.wav
Normal file
BIN
src/android/sample/speechDemo/src/main/assets/keys
Normal file
1
src/android/sample/speechDemo/src/main/assets/userwords
Normal file
@ -0,0 +1 @@
|
||||
{"userword":[{"name":"我的常用词","words":["佳晨实业","蜀南庭苑","高兰路","复联二"]},{"name":"我的好友","words":["李馨琪","鹿晓雷","张集栋","周家莉","叶震珂","熊泽萌"]}]}
|
@ -0,0 +1,23 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result;
|
||||
|
||||
/**
|
||||
* <p>Title: FinalResult</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月14日 上午11:12:58
|
||||
*/
|
||||
public class FinalResult extends Result {
|
||||
|
||||
public int ret;
|
||||
|
||||
public float total_score;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "返回值:" + ret + ",总分:" + total_score;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result;
|
||||
|
||||
import com.iflytek.ise.result.util.ResultFormatUtil;
|
||||
|
||||
/**
|
||||
* <p>Title: ReadSentenceResult</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午5:04:14
|
||||
*/
|
||||
public class ReadSentenceResult extends Result {
|
||||
|
||||
public ReadSentenceResult() {
|
||||
category = "read_sentence";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
if ("cn".equals(language)) {
|
||||
buffer.append("[总体结果]\n")
|
||||
.append("评测内容:" + content + "\n")
|
||||
.append("朗读时长:" + time_len + "\n")
|
||||
.append("总分:" + total_score + "\n\n")
|
||||
.append("[朗读详情]").append(ResultFormatUtil.formatDetails_CN(sentences));
|
||||
} else {
|
||||
if (is_rejected) {
|
||||
buffer.append("检测到乱读,")
|
||||
.append("except_info:" + except_info + "\n\n"); // except_info代码说明详见《语音评测参数、结果说明文档》
|
||||
}
|
||||
|
||||
buffer.append("[总体结果]\n")
|
||||
.append("评测内容:" + content + "\n")
|
||||
.append("总分:" + total_score + "\n\n")
|
||||
.append("[朗读详情]").append(ResultFormatUtil.formatDetails_EN(sentences));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result;
|
||||
|
||||
import com.iflytek.ise.result.util.ResultFormatUtil;
|
||||
|
||||
/**
|
||||
* <p>Title: ReadSyllableResult</p>
|
||||
* <p>Description: 中文单字评测结果</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午5:03:14
|
||||
*/
|
||||
public class ReadSyllableResult extends Result {
|
||||
|
||||
public ReadSyllableResult() {
|
||||
language = "cn";
|
||||
category = "read_syllable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("[总体结果]\n")
|
||||
.append("评测内容:" + content + "\n")
|
||||
.append("朗读时长:" + time_len + "\n")
|
||||
.append("总分:" + total_score + "\n\n")
|
||||
.append("[朗读详情]").append(ResultFormatUtil.formatDetails_CN(sentences));
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result;
|
||||
|
||||
import com.iflytek.ise.result.util.ResultFormatUtil;
|
||||
|
||||
/**
|
||||
* <p>Title: ReadWordResult</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午5:03:50
|
||||
*/
|
||||
public class ReadWordResult extends Result {
|
||||
|
||||
public ReadWordResult() {
|
||||
category = "read_word";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
if ("cn".equals(language)) {
|
||||
buffer.append("[总体结果]\n")
|
||||
.append("评测内容:" + content + "\n")
|
||||
.append("朗读时长:" + time_len + "\n")
|
||||
.append("总分:" + total_score + "\n\n")
|
||||
.append("[朗读详情]")
|
||||
.append(ResultFormatUtil.formatDetails_CN(sentences));
|
||||
} else {
|
||||
if (is_rejected) {
|
||||
buffer.append("检测到乱读,")
|
||||
.append("except_info:" + except_info + "\n\n"); // except_info代码说明详见《语音评测参数、结果说明文档》
|
||||
}
|
||||
|
||||
buffer.append("[总体结果]\n")
|
||||
.append("评测内容:" + content + "\n")
|
||||
.append("总分:" + total_score + "\n\n")
|
||||
.append("[朗读详情]")
|
||||
.append(ResultFormatUtil.formatDetails_EN(sentences));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.iflytek.ise.result.entity.Sentence;
|
||||
|
||||
/**
|
||||
* <p>Title: Result</p>
|
||||
* <p>Description: 评测结果</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午4:58:38
|
||||
*/
|
||||
public class Result {
|
||||
/**
|
||||
* 评测语种:en(英文)、cn(中文)
|
||||
*/
|
||||
public String language;
|
||||
/**
|
||||
* 评测种类:read_syllable(cn单字)、read_word(词语)、read_sentence(句子)
|
||||
*/
|
||||
public String category;
|
||||
/**
|
||||
* 开始帧位置,每帧相当于10ms
|
||||
*/
|
||||
public int beg_pos;
|
||||
/**
|
||||
* 结束帧位置
|
||||
*/
|
||||
public int end_pos;
|
||||
/**
|
||||
* 评测内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 总得分
|
||||
*/
|
||||
public float total_score;
|
||||
/**
|
||||
* 时长(cn)
|
||||
*/
|
||||
public int time_len;
|
||||
/**
|
||||
* 异常信息(en)
|
||||
*/
|
||||
public String except_info;
|
||||
/**
|
||||
* 是否乱读(cn)
|
||||
*/
|
||||
public boolean is_rejected;
|
||||
/**
|
||||
* xml结果中的sentence标签
|
||||
*/
|
||||
public ArrayList<Sentence> sentences;
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result.entity;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* <p>Title: Phone</p>
|
||||
* <p>Description: 音素,对应于xml结果中的Phone标签</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午3:55:56
|
||||
*/
|
||||
public class Phone {
|
||||
/**
|
||||
* 讯飞音标-标准音标映射表(en)
|
||||
*/
|
||||
public static HashMap<String, String> phone_map = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
phone_map.put("aa", "ɑ:");
|
||||
phone_map.put("oo", "ɔ");
|
||||
phone_map.put("ae", "æ");
|
||||
phone_map.put("ah", "ʌ");
|
||||
phone_map.put("ao", "ɔ:");
|
||||
phone_map.put("aw", "aʊ");
|
||||
phone_map.put("ax", "ə");
|
||||
phone_map.put("ay", "aɪ");
|
||||
phone_map.put("eh", "e");
|
||||
phone_map.put("er", "ə:");
|
||||
phone_map.put("ey", "eɪ");
|
||||
phone_map.put("ih", "ɪ");
|
||||
phone_map.put("iy", "i:");
|
||||
phone_map.put("ow", "əʊ");
|
||||
phone_map.put("oy", "ɔɪ");
|
||||
phone_map.put("uh", "ʊ");
|
||||
phone_map.put("uw", "ʊ:");
|
||||
phone_map.put("ch", "tʃ");
|
||||
phone_map.put("dh", "ð");
|
||||
phone_map.put("hh", "h");
|
||||
phone_map.put("jh", "dʒ");
|
||||
phone_map.put("ng", "ŋ");
|
||||
phone_map.put("sh", "ʃ");
|
||||
phone_map.put("th", "θ");
|
||||
phone_map.put("zh", "ʒ");
|
||||
phone_map.put("y", "j");
|
||||
phone_map.put("d", "d");
|
||||
phone_map.put("k", "k");
|
||||
phone_map.put("l", "l");
|
||||
phone_map.put("m", "m");
|
||||
phone_map.put("n", "n");
|
||||
phone_map.put("b", "b");
|
||||
phone_map.put("f", "f");
|
||||
phone_map.put("g", "g");
|
||||
phone_map.put("p", "p");
|
||||
phone_map.put("r", "r");
|
||||
phone_map.put("s", "s");
|
||||
phone_map.put("t", "t");
|
||||
phone_map.put("v", "v");
|
||||
phone_map.put("w", "w");
|
||||
phone_map.put("z", "z");
|
||||
phone_map.put("ar", "eə");
|
||||
phone_map.put("ir", "iə");
|
||||
phone_map.put("ur", "ʊə");
|
||||
phone_map.put("tr", "tr");
|
||||
phone_map.put("dr", "dr");
|
||||
phone_map.put("ts", "ts");
|
||||
phone_map.put("dz", "dz");
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始帧位置,每帧相当于10ms
|
||||
*/
|
||||
public int beg_pos;
|
||||
/**
|
||||
* 结束帧位置
|
||||
*/
|
||||
public int end_pos;
|
||||
/**
|
||||
* 音素内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 增漏读信息:0(正确),16(漏读),32(增读),64(回读),128(替换)
|
||||
*/
|
||||
public int dp_message;
|
||||
/**
|
||||
* 时长(单位:帧,每帧相当于10ms)(cn)
|
||||
*/
|
||||
public int time_len;
|
||||
|
||||
/**
|
||||
* 得到content对应的标准音标(en)
|
||||
*/
|
||||
public String getStdSymbol() {
|
||||
return getStdSymbol(content);
|
||||
}
|
||||
|
||||
public static String getStdSymbol(String content) {
|
||||
String std = phone_map.get(content);
|
||||
return (null == std)? content: std;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p>Title: Sentence</p>
|
||||
* <p>Description: 句子,对应于xml结果中的sentence标签</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午4:10:09
|
||||
*/
|
||||
public class Sentence {
|
||||
/**
|
||||
* 开始帧位置,每帧相当于10ms
|
||||
*/
|
||||
public int beg_pos;
|
||||
/**
|
||||
* 结束帧位置
|
||||
*/
|
||||
public int end_pos;
|
||||
/**
|
||||
* 句子内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 总得分
|
||||
*/
|
||||
public float total_score;
|
||||
/**
|
||||
* 时长(单位:帧,每帧相当于10ms)(cn)
|
||||
*/
|
||||
public int time_len;
|
||||
/**
|
||||
* 句子的索引(en)
|
||||
*/
|
||||
public int index;
|
||||
/**
|
||||
* 单词数(en)
|
||||
*/
|
||||
public int word_count;
|
||||
/**
|
||||
* sentence包括的word
|
||||
*/
|
||||
public ArrayList<Word> words;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p>Title: Syll</p>
|
||||
* <p>Description: 音节,对应于结果xml中的Syll标签</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午3:49:51
|
||||
*/
|
||||
public class Syll {
|
||||
/**
|
||||
* 开始帧位置,每帧相当于10ms
|
||||
*/
|
||||
public int beg_pos;
|
||||
/**
|
||||
* 结束帧位置
|
||||
*/
|
||||
public int end_pos;
|
||||
/**
|
||||
* 音节内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 拼音(cn),数字代表声调,5表示轻声,如fen1
|
||||
*/
|
||||
public String symbol;
|
||||
/**
|
||||
* 增漏读信息:0(正确),16(漏读),32(增读),64(回读),128(替换)
|
||||
*/
|
||||
public int dp_message;
|
||||
/**
|
||||
* 时长(单位:帧,每帧相当于10ms)(cn)
|
||||
*/
|
||||
public int time_len;
|
||||
/**
|
||||
* Syll包含的音节
|
||||
*/
|
||||
public ArrayList<Phone> phones;
|
||||
|
||||
/**
|
||||
* 获取音节的标准音标(en)
|
||||
*
|
||||
* @return 标准音标
|
||||
*/
|
||||
public String getStdSymbol() {
|
||||
String stdSymbol = "";
|
||||
String[] symbols = content.split(" ");
|
||||
|
||||
for (int i = 0; i < symbols.length; i++) {
|
||||
stdSymbol += Phone.getStdSymbol(symbols[i]);
|
||||
}
|
||||
|
||||
return stdSymbol;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p>Title: Word</p>
|
||||
* <p>Description: 单词,对应于结果xml中的word标签</p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午3:29:30
|
||||
*/
|
||||
public class Word {
|
||||
/**
|
||||
* 开始帧位置,每帧相当于10ms
|
||||
*/
|
||||
public int beg_pos;
|
||||
/**
|
||||
* 结束帧位置
|
||||
*/
|
||||
public int end_pos;
|
||||
/**
|
||||
* 单词内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 增漏读信息:0(正确),16(漏读),32(增读),64(回读),128(替换)
|
||||
*/
|
||||
public int dp_message;
|
||||
/**
|
||||
* 单词在全篇索引(en)
|
||||
*/
|
||||
public int global_index;
|
||||
/**
|
||||
* 单词在句子中的索引(en)
|
||||
*/
|
||||
public int index;
|
||||
/**
|
||||
* 拼音(cn),数字代表声调,5表示轻声,如fen1
|
||||
*/
|
||||
public String symbol;
|
||||
/**
|
||||
* 时长(单位:帧,每帧相当于10ms)(cn)
|
||||
*/
|
||||
public int time_len;
|
||||
/**
|
||||
* 单词得分(en)
|
||||
*/
|
||||
public float total_score;
|
||||
/**
|
||||
* Word包含的Syll
|
||||
*/
|
||||
public ArrayList<Syll> sylls;
|
||||
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>Title: ResultFormatUtl</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月19日 上午10:01:14
|
||||
*/
|
||||
public class ResultFormatUtil {
|
||||
|
||||
/**
|
||||
* 将英语评测详情按格式输出
|
||||
*
|
||||
* @param sentences
|
||||
* @return 英语评测详情
|
||||
*/
|
||||
public static String formatDetails_EN(ArrayList<Sentence> sentences) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (null == sentences) {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
for (Sentence sentence: sentences ) {
|
||||
if ("噪音".equals(ResultTranslateUtil.getContent(sentence.content))
|
||||
|| "静音".equals(ResultTranslateUtil.getContent(sentence.content))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null == sentence.words) {
|
||||
continue;
|
||||
}
|
||||
for (Word word: sentence.words) {
|
||||
if ("噪音".equals(ResultTranslateUtil.getContent(word.content))
|
||||
|| "静音".equals(ResultTranslateUtil.getContent(word.content))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer.append("\n单词[" + ResultTranslateUtil.getContent(word.content) + "] ")
|
||||
.append("朗读:" + ResultTranslateUtil.getDpMessageInfo(word.dp_message))
|
||||
.append(" 得分:" + word.total_score);
|
||||
if (null == word.sylls) {
|
||||
buffer.append("\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Syll syll: word.sylls) {
|
||||
buffer.append("\n└音节[" + ResultTranslateUtil.getContent(syll.getStdSymbol()) + "] ");
|
||||
if (null == syll.phones) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Phone phone: syll.phones) {
|
||||
buffer.append("\n\t└音素[" + ResultTranslateUtil.getContent(phone.getStdSymbol()) + "] ")
|
||||
.append(" 朗读:" + ResultTranslateUtil.getDpMessageInfo(phone.dp_message));
|
||||
}
|
||||
|
||||
}
|
||||
buffer.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将汉语评测详情按格式输出
|
||||
*
|
||||
* @param sentences
|
||||
* @return 汉语评测详情
|
||||
*/
|
||||
public static String formatDetails_CN(ArrayList<Sentence> sentences) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (null == sentences) {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
for (Sentence sentence: sentences ) {
|
||||
if (null == sentence.words) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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) {
|
||||
if ("噪音".equals(ResultTranslateUtil.getContent(syll.content))
|
||||
|| "静音".equals(ResultTranslateUtil.getContent(syll.content))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer.append("\n└音节[" + ResultTranslateUtil.getContent(syll.content) + "] " + syll.symbol + " 时长:" + syll.time_len);
|
||||
if (null == syll.phones) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Phone phone: syll.phones) {
|
||||
buffer.append("\n\t└音素[" + ResultTranslateUtil.getContent(phone.content) + "] " + "时长:" + phone.time_len)
|
||||
.append(" 朗读:" + ResultTranslateUtil.getDpMessageInfo(phone.dp_message));
|
||||
}
|
||||
|
||||
}
|
||||
buffer.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.ise.result.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* <p>Title: ResultTranslateUtl</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月13日 下午6:05:03
|
||||
*/
|
||||
public class ResultTranslateUtil {
|
||||
|
||||
private static HashMap<Integer, String> dp_message_map = new HashMap<Integer, String>();
|
||||
private static HashMap<String, String> special_content_map = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
dp_message_map.put(0, "正常");
|
||||
dp_message_map.put(16, "漏读");
|
||||
dp_message_map.put(32, "增读");
|
||||
dp_message_map.put(64, "回读");
|
||||
dp_message_map.put(128, "替换");
|
||||
|
||||
special_content_map.put("sil", "静音");
|
||||
special_content_map.put("silv", "静音");
|
||||
special_content_map.put("fil", "噪音");
|
||||
}
|
||||
|
||||
public static String getDpMessageInfo(int dp_message) {
|
||||
return dp_message_map.get(dp_message);
|
||||
}
|
||||
|
||||
public static String getContent(String content) {
|
||||
String val = special_content_map.get(content);
|
||||
return (null == val)? content: val;
|
||||
}
|
||||
}
|
@ -0,0 +1,279 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
import com.iflytek.ise.result.FinalResult;
|
||||
import com.iflytek.ise.result.ReadSentenceResult;
|
||||
import com.iflytek.ise.result.ReadSyllableResult;
|
||||
import com.iflytek.ise.result.ReadWordResult;
|
||||
import com.iflytek.ise.result.Result;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>Title: XmlResultParser</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Company: www.iflytek.com</p>
|
||||
* @author iflytek
|
||||
* @date 2015年1月12日 下午5:21:53
|
||||
*/
|
||||
public class XmlResultParser {
|
||||
|
||||
public Result parse(String xml) {
|
||||
if (TextUtils.isEmpty(xml)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
XmlPullParser pullParser = Xml.newPullParser();
|
||||
|
||||
try {
|
||||
InputStream ins = new ByteArrayInputStream(xml.getBytes());
|
||||
pullParser.setInput(ins, "utf-8");
|
||||
FinalResult finalResult = null;
|
||||
|
||||
int eventType = pullParser.getEventType();
|
||||
while (XmlPullParser.END_DOCUMENT != eventType) {
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
if ("FinalResult".equals(pullParser.getName())) {
|
||||
// 只有一个总分的结果
|
||||
finalResult = new FinalResult();
|
||||
} else if ("ret".equals(pullParser.getName())) {
|
||||
finalResult.ret = getInt(pullParser, "value");
|
||||
} else if ("total_score".equals(pullParser.getName())) {
|
||||
finalResult.total_score = getFloat(pullParser, "value");
|
||||
} else if ("xml_result".equals(pullParser.getName())) {
|
||||
// 详细结果
|
||||
return parseResult(pullParser);
|
||||
}
|
||||
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if ("FinalResult".equals(pullParser.getName())) {
|
||||
return finalResult;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
eventType = pullParser.next();
|
||||
}
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Result parseResult(XmlPullParser pullParser) {
|
||||
Result result = null;
|
||||
// <rec_paper>标签是否已扫描到
|
||||
boolean rec_paperPassed = false;
|
||||
Sentence sentence = null;
|
||||
Word word = null;
|
||||
Syll syll = null;
|
||||
Phone phone = null;
|
||||
|
||||
int eventType;
|
||||
try {
|
||||
eventType = pullParser.getEventType();
|
||||
while (XmlPullParser.END_DOCUMENT != eventType) {
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
if ("rec_paper".equals(pullParser.getName())) {
|
||||
rec_paperPassed = true;
|
||||
} else if ("read_syllable".equals(pullParser.getName())) {
|
||||
if (!rec_paperPassed) {
|
||||
result = new ReadSyllableResult();
|
||||
} else {
|
||||
readTotalResult(result, pullParser);
|
||||
}
|
||||
} else if ("read_word".equals(pullParser.getName())) {
|
||||
if (!rec_paperPassed) {
|
||||
result = new ReadWordResult();
|
||||
String lan = getLanguage(pullParser);
|
||||
result.language = (null == lan)? "cn": lan;
|
||||
} else {
|
||||
readTotalResult(result, pullParser);
|
||||
}
|
||||
} else if ("read_sentence".equals(pullParser.getName()) ||
|
||||
"read_chapter".equals(pullParser.getName())) {
|
||||
if (!rec_paperPassed) {
|
||||
result = new ReadSentenceResult();
|
||||
String lan = getLanguage(pullParser);
|
||||
result.language = (null == lan)? "cn": lan;
|
||||
} else {
|
||||
readTotalResult(result, pullParser);
|
||||
}
|
||||
} else if ("sentence".equals(pullParser.getName())) {
|
||||
if (null == result.sentences) {
|
||||
result.sentences = new ArrayList<Sentence>();
|
||||
}
|
||||
sentence = createSentence(pullParser);
|
||||
} else if ("word".equals(pullParser.getName())) {
|
||||
if (null != sentence && null == sentence.words) {
|
||||
sentence.words = new ArrayList<Word>();
|
||||
}
|
||||
word = createWord(pullParser);
|
||||
} else if ("syll".equals(pullParser.getName())) {
|
||||
if (null != word && null == word.sylls) {
|
||||
word.sylls = new ArrayList<Syll>();
|
||||
}
|
||||
syll = createSyll(pullParser);
|
||||
} else if ("phone".equals(pullParser.getName())) {
|
||||
if (null != syll && null == syll.phones) {
|
||||
syll.phones = new ArrayList<Phone>();
|
||||
}
|
||||
phone = createPhone(pullParser);
|
||||
}
|
||||
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if ("phone".equals(pullParser.getName())) {
|
||||
syll.phones.add(phone);
|
||||
} else if ("syll".equals(pullParser.getName())) {
|
||||
word.sylls.add(syll);
|
||||
} else if ("word".equals(pullParser.getName())) {
|
||||
sentence.words.add(word);
|
||||
} else if ("sentence".equals(pullParser.getName())) {
|
||||
result.sentences.add(sentence);
|
||||
} else if ("read_syllable".equals(pullParser.getName())
|
||||
|| "read_word".equals(pullParser.getName())
|
||||
|| "read_sentence".equals(pullParser.getName())) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
eventType = pullParser.next();
|
||||
}
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void readTotalResult(Result result, XmlPullParser pullParser) {
|
||||
result.beg_pos = getInt(pullParser, "beg_pos");
|
||||
result.end_pos = getInt(pullParser, "end_pos");
|
||||
result.content = getContent(pullParser);
|
||||
result.total_score = getFloat(pullParser, "total_score");
|
||||
result.time_len = getInt(pullParser, "time_len");
|
||||
result.except_info = getExceptInfo(pullParser);
|
||||
result.is_rejected = getIsRejected(pullParser);
|
||||
}
|
||||
|
||||
private Phone createPhone(XmlPullParser pullParser) {
|
||||
Phone phone;
|
||||
phone = new Phone();
|
||||
phone.beg_pos = getInt(pullParser, "beg_pos");
|
||||
phone.end_pos = getInt(pullParser, "end_pos");
|
||||
phone.content = getContent(pullParser);
|
||||
phone.dp_message = getInt(pullParser, "dp_message");
|
||||
phone.time_len = getInt(pullParser, "time_len");
|
||||
return phone;
|
||||
}
|
||||
|
||||
private Syll createSyll(XmlPullParser pullParser) {
|
||||
Syll syll;
|
||||
syll = new Syll();
|
||||
syll.beg_pos = getInt(pullParser, "beg_pos");
|
||||
syll.end_pos = getInt(pullParser, "end_pos");
|
||||
syll.content = getContent(pullParser);
|
||||
syll.symbol = getSymbol(pullParser);
|
||||
syll.dp_message = getInt(pullParser, "dp_message");
|
||||
syll.time_len = getInt(pullParser, "time_len");
|
||||
return syll;
|
||||
}
|
||||
|
||||
private Word createWord(XmlPullParser pullParser) {
|
||||
Word word;
|
||||
word = new Word();
|
||||
word.beg_pos = getInt(pullParser, "beg_pos");
|
||||
word.end_pos = getInt(pullParser, "end_pos");
|
||||
word.content = getContent(pullParser);
|
||||
word.symbol = getSymbol(pullParser);
|
||||
word.time_len = getInt(pullParser, "time_len");
|
||||
word.dp_message = getInt(pullParser, "dp_message");
|
||||
word.total_score = getFloat(pullParser, "total_score");
|
||||
word.global_index = getInt(pullParser, "global_index");
|
||||
word.index = getInt(pullParser, "index");
|
||||
return word;
|
||||
}
|
||||
|
||||
private Sentence createSentence(XmlPullParser pullParser) {
|
||||
Sentence sentence;
|
||||
sentence = new Sentence();
|
||||
sentence.beg_pos = getInt(pullParser, "beg_pos");
|
||||
sentence.end_pos = getInt(pullParser, "end_pos");
|
||||
sentence.content = getContent(pullParser);
|
||||
sentence.time_len = getInt(pullParser, "time_len");
|
||||
sentence.index = getInt(pullParser, "index");
|
||||
sentence.word_count = getInt(pullParser, "word_count");
|
||||
return sentence;
|
||||
}
|
||||
|
||||
private String getLanguage(XmlPullParser pullParser) {
|
||||
return pullParser.getAttributeValue(null, "lan");
|
||||
}
|
||||
|
||||
private String getExceptInfo(XmlPullParser pullParser) {
|
||||
return pullParser.getAttributeValue(null, "except_info");
|
||||
}
|
||||
|
||||
private boolean getIsRejected(XmlPullParser pullParser) {
|
||||
String isRejected = pullParser.getAttributeValue(null, "is_rejected");
|
||||
if (null == isRejected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Boolean.parseBoolean(isRejected);
|
||||
}
|
||||
|
||||
private String getSymbol(XmlPullParser pullParser) {
|
||||
return pullParser.getAttributeValue(null, "symbol");
|
||||
}
|
||||
|
||||
private float getFloat(XmlPullParser pullParser, String attrName) {
|
||||
String val = pullParser.getAttributeValue(null, attrName);
|
||||
if (null == val) {
|
||||
return 0f;
|
||||
}
|
||||
return Float.parseFloat(val);
|
||||
}
|
||||
|
||||
private String getContent(XmlPullParser pullParser) {
|
||||
return pullParser.getAttributeValue(null, "content");
|
||||
}
|
||||
|
||||
private int getInt(XmlPullParser pullParser, String attrName) {
|
||||
String val = pullParser.getAttributeValue(null, attrName);
|
||||
if (null == val) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.parseInt(val);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.iflytek.speech.setting;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.view.Window;
|
||||
|
||||
import com.iflytek.speech.util.SettingTextWatcher;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
/**
|
||||
* 听写设置界面
|
||||
*/
|
||||
public class IatSettings extends PreferenceActivity implements OnPreferenceChangeListener {
|
||||
|
||||
public static final String PREFER_NAME = "com.iflytek.setting";
|
||||
private EditTextPreference mVadbosPreference;
|
||||
private EditTextPreference mVadeosPreference;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
||||
addPreferencesFromResource(R.xml.iat_setting);
|
||||
|
||||
mVadbosPreference = (EditTextPreference)findPreference("iat_vadbos_preference");
|
||||
mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadbosPreference,0,10000));
|
||||
|
||||
mVadeosPreference = (EditTextPreference)findPreference("iat_vadeos_preference");
|
||||
mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this,mVadeosPreference,0,10000));
|
||||
}
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.iflytek.speech.setting;
|
||||
|
||||
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.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
/**
|
||||
* 评测设置界面
|
||||
*/
|
||||
public class IseSettings extends PreferenceActivity {
|
||||
private final static String PREFER_NAME = "ise_settings";
|
||||
|
||||
private ListPreference mLanguagePref;
|
||||
private ListPreference mCategoryPref;
|
||||
private ListPreference mResultLevelPref;
|
||||
private EditTextPreference mVadBosPref;
|
||||
private EditTextPreference mVadEosPref;
|
||||
private EditTextPreference mSpeechTimeoutPref;
|
||||
|
||||
private Toast mToast;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
||||
addPreferencesFromResource(R.xml.ise_settings);
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE);
|
||||
mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY);
|
||||
mResultLevelPref = (ListPreference) findPreference(SpeechConstant.RESULT_LEVEL);
|
||||
mVadBosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_BOS);
|
||||
mVadEosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_EOS);
|
||||
mSpeechTimeoutPref = (EditTextPreference) findPreference(SpeechConstant.KEY_SPEECH_TIMEOUT);
|
||||
|
||||
mToast = Toast.makeText(IseSettings.this, "", Toast.LENGTH_LONG);
|
||||
|
||||
mLanguagePref.setSummary("当前:" + mLanguagePref.getEntry());
|
||||
mCategoryPref.setSummary("当前:" + mCategoryPref.getEntry());
|
||||
mResultLevelPref.setSummary("当前:" + mResultLevelPref.getEntry());
|
||||
mVadBosPref.setSummary("当前:" + mVadBosPref.getText() + "ms");
|
||||
mVadEosPref.setSummary("当前:" + mVadEosPref.getText() + "ms");
|
||||
|
||||
String speech_timeout = mSpeechTimeoutPref.getText();
|
||||
String summary = "当前:" + speech_timeout;
|
||||
if (!"-1".equals(speech_timeout)) {
|
||||
summary += "ms";
|
||||
}
|
||||
mSpeechTimeoutPref.setSummary(summary);
|
||||
|
||||
mLanguagePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if ("zh_cn".equals(newValue.toString())) {
|
||||
if ("plain".equals(mResultLevelPref.getValue())) {
|
||||
showTip("汉语评测结果格式不支持plain设置");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ("read_syllable".equals(mCategoryPref.getValue())) {
|
||||
showTip("英语评测不支持单字");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int newValueIndex = mLanguagePref.findIndexOfValue(newValue.toString());
|
||||
String newEntry = (String) mLanguagePref.getEntries()[newValueIndex];
|
||||
mLanguagePref.setSummary("当前:" + newEntry);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mCategoryPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if ("en_us".equals(mLanguagePref.getValue()) && "read_syllable".equals(newValue.toString())) {
|
||||
showTip("英语评测不支持单字,请选其他项");
|
||||
return false;
|
||||
}
|
||||
|
||||
int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString());
|
||||
String newEntry = (String) mCategoryPref.getEntries()[newValueIndex];
|
||||
mCategoryPref.setSummary("当前:" + newEntry);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mResultLevelPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if ("zh_cn".equals(mLanguagePref.getValue()) && "plain".equals(newValue.toString())) {
|
||||
showTip("汉语评测不支持plain,请选其他项");
|
||||
return false;
|
||||
}
|
||||
|
||||
mResultLevelPref.setSummary("当前:" + newValue.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mVadBosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
mVadBosPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int bos;
|
||||
try {
|
||||
bos = Integer.parseInt(newValue.toString());
|
||||
} catch (Exception e) {
|
||||
showTip("无效输入!");
|
||||
return false;
|
||||
}
|
||||
if (bos < 0 || bos > 30000) {
|
||||
showTip("取值范围为0~30000");
|
||||
return false;
|
||||
}
|
||||
|
||||
mVadBosPref.setSummary("当前:" + bos + "ms");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mVadEosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
mVadEosPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int eos;
|
||||
try {
|
||||
eos = Integer.parseInt(newValue.toString());
|
||||
} catch (Exception e) {
|
||||
showTip("无效输入!");
|
||||
return false;
|
||||
}
|
||||
if (eos < 0 || eos > 30000) {
|
||||
showTip("取值范围为0~30000");
|
||||
return false;
|
||||
}
|
||||
|
||||
mVadEosPref.setSummary("当前:" + eos + "ms");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mSpeechTimeoutPref.getEditText().setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_CLASS_NUMBER);
|
||||
mSpeechTimeoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int speech_timeout;
|
||||
try {
|
||||
speech_timeout = Integer.parseInt(newValue.toString());
|
||||
} catch (Exception e) {
|
||||
showTip("无效输入!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (speech_timeout < -1) {
|
||||
showTip("必须大于等于-1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (speech_timeout == -1) {
|
||||
mSpeechTimeoutPref.setSummary("当前:-1");
|
||||
} else {
|
||||
mSpeechTimeoutPref.setSummary("当前:" + speech_timeout + "ms");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showTip(String str) {
|
||||
if(!TextUtils.isEmpty(str)) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.iflytek.speech.setting;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.view.Window;
|
||||
|
||||
import com.iflytek.speech.util.SettingTextWatcher;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
|
||||
/**
|
||||
* 合成设置界面
|
||||
*/
|
||||
public class TtsSettings extends PreferenceActivity implements OnPreferenceChangeListener {
|
||||
|
||||
public static final String PREFER_NAME = "com.iflytek.setting";
|
||||
private EditTextPreference mSpeedPreference;
|
||||
private EditTextPreference mPitchPreference;
|
||||
private EditTextPreference mVolumePreference;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
// 指定保存文件名字
|
||||
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
||||
addPreferencesFromResource(R.xml.tts_setting);
|
||||
mSpeedPreference = (EditTextPreference)findPreference("speed_preference");
|
||||
mSpeedPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mSpeedPreference,0,200));
|
||||
|
||||
mPitchPreference = (EditTextPreference)findPreference("pitch_preference");
|
||||
mPitchPreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mPitchPreference,0,100));
|
||||
|
||||
mVolumePreference = (EditTextPreference)findPreference("volume_preference");
|
||||
mVolumePreference.getEditText().addTextChangedListener(new SettingTextWatcher(TtsSettings.this,mVolumePreference,0,100));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* @author hjyu
|
||||
* @date 2018/5/31.
|
||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||
*/
|
||||
|
||||
public class UrlSettings extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
public static final String PREFER_NAME = "com.iflytek.setting";
|
||||
private ListPreference url_preference;
|
||||
private EditTextPreference url_edit;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
|
||||
addPreferencesFromResource(R.xml.url_setting);
|
||||
|
||||
url_preference = (ListPreference)findPreference("url_preference");
|
||||
url_preference.setSummary("当前:" + url_preference.getEntry());
|
||||
url_preference.setOnPreferenceChangeListener(this);
|
||||
|
||||
|
||||
url_edit = (EditTextPreference) findPreference("url_edit");
|
||||
url_edit.setSummary("当前域名:" + url_edit.getText());
|
||||
url_edit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
url_edit.setSummary("当前机房:" + newValue.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int newValueIndex = url_preference.findIndexOfValue(newValue.toString());
|
||||
String newEntry = (String) url_preference.getEntries()[newValueIndex];
|
||||
url_preference.setSummary("当前:" + newEntry);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
* @author MatrixCV
|
||||
* FaceRect是用于表示人脸检测的结果,其中包括了 人脸的角度、得分、检测框位置、关键点
|
||||
*/
|
||||
public class FaceRect {
|
||||
public float score;
|
||||
|
||||
public Rect bound = new Rect();
|
||||
public Point point[];
|
||||
|
||||
public Rect raw_bound = new Rect();
|
||||
public Point raw_point[];
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return bound.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,269 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FaceUtil {
|
||||
public final static int REQUEST_PICTURE_CHOOSE = 1;
|
||||
public final static int REQUEST_CAMERA_IMAGE = 2;
|
||||
public final static int REQUEST_CROP_IMAGE = 3;
|
||||
|
||||
/***
|
||||
* 裁剪图片
|
||||
* @param activity Activity
|
||||
* @param uri 图片的Uri
|
||||
*/
|
||||
public static void cropPicture(Activity activity, Uri uri) {
|
||||
Intent innerIntent = new Intent("com.android.camera.action.CROP");
|
||||
innerIntent.setDataAndType(uri, "image/*");
|
||||
innerIntent.putExtra("crop", "true");// 才能出剪辑的小方框,不然没有剪辑功能,只能选取图片
|
||||
innerIntent.putExtra("aspectX", 1); // 放大缩小比例的X
|
||||
innerIntent.putExtra("aspectY", 1);// 放大缩小比例的X 这里的比例为: 1:1
|
||||
innerIntent.putExtra("outputX", 320); //这个是限制输出图片大小
|
||||
innerIntent.putExtra("outputY", 320);
|
||||
innerIntent.putExtra("return-data", true);
|
||||
// 切图大小不足输出,无黑框
|
||||
innerIntent.putExtra("scale", true);
|
||||
innerIntent.putExtra("scaleUpIfNeeded", true);
|
||||
File imageFile = new File(getImagePath(activity.getApplicationContext()));
|
||||
innerIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
|
||||
innerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
|
||||
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("/")) {
|
||||
path += "/";
|
||||
}
|
||||
|
||||
File folder = new File(path);
|
||||
if (folder != null && !folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
path += "ifd.jpg";
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取图片属性:旋转的角度
|
||||
*
|
||||
* @param path 图片绝对路径
|
||||
* @return degree 旋转角度
|
||||
*/
|
||||
public static int readPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 旋转图片
|
||||
*
|
||||
* @param angle 旋转角度
|
||||
* @param bitmap 原图
|
||||
* @return bitmap 旋转后的图片
|
||||
*/
|
||||
public static Bitmap rotateImage(int angle, Bitmap bitmap) {
|
||||
// 图片旋转矩阵
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(angle);
|
||||
// 得到旋转后的图片
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
|
||||
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
return resizedBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在指定画布上将人脸框出来
|
||||
*
|
||||
* @param canvas 给定的画布
|
||||
* @param face 需要绘制的人脸信息
|
||||
* @param width 原图宽
|
||||
* @param height 原图高
|
||||
* @param frontCamera 是否为前置摄像头,如为前置摄像头需左右对称
|
||||
* @param DrawOriRect 可绘制原始框,也可以只画四个角
|
||||
*/
|
||||
static public void drawFaceRect(Canvas canvas, FaceRect face, int width, int height, boolean frontCamera, boolean DrawOriRect) {
|
||||
if(canvas == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(Color.rgb(255, 203, 15));
|
||||
int len = (face.bound.bottom - face.bound.top) / 8;
|
||||
if (len / 8 >= 2) paint.setStrokeWidth(len / 8);
|
||||
else paint.setStrokeWidth(2);
|
||||
|
||||
Rect rect = face.bound;
|
||||
|
||||
if(frontCamera) {
|
||||
int top = rect.top;
|
||||
rect.top = width - rect.bottom;
|
||||
rect.bottom = width - top;
|
||||
}
|
||||
|
||||
if (DrawOriRect) {
|
||||
paint.setStyle(Style.STROKE);
|
||||
canvas.drawRect(rect, paint);
|
||||
} else {
|
||||
int drawl = rect.left - len;
|
||||
int drawr = rect.right + len;
|
||||
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);
|
||||
}
|
||||
|
||||
if (face.point != null) {
|
||||
for (Point p : face.point)
|
||||
{
|
||||
if(frontCamera) {
|
||||
p.y = width - p.y;
|
||||
}
|
||||
canvas.drawPoint(p.x, p.y, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将矩形随原图顺时针旋转90度
|
||||
*
|
||||
* @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.top = left;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将点随原图顺时针旋转90度
|
||||
* @param p
|
||||
* 待旋转的点
|
||||
*
|
||||
* @param width
|
||||
* 输入点对应的原图宽
|
||||
*
|
||||
* @param height
|
||||
* 输入点对应的原图宽
|
||||
*
|
||||
* @return
|
||||
* 旋转后的点
|
||||
*/
|
||||
static public Point RotateDeg90(Point p, int width, int height) {
|
||||
int x = p.x;
|
||||
p.x = height - p.y;
|
||||
p.y = x;
|
||||
return p;
|
||||
}
|
||||
|
||||
public static int getNumCores() {
|
||||
class CpuFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if(Pattern.matches("cpu[0-9]", pathname.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
File dir = new File("/sys/devices/system/cpu/");
|
||||
File[] files = dir.listFiles(new CpuFilter());
|
||||
return files.length;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存Bitmap至本地
|
||||
* @param Bitmap
|
||||
*/
|
||||
public static void saveBitmapToFile(Context context,Bitmap bmp){
|
||||
String file_path = getImagePath(context);
|
||||
File file = new File(file_path);
|
||||
FileOutputStream fOut;
|
||||
try {
|
||||
fOut = new FileOutputStream(file);
|
||||
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
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 com.iflytek.cloud.ErrorCode;
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
import com.iflytek.cloud.SpeechUtility;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* 功能性函数扩展类
|
||||
*/
|
||||
public class FucUtil {
|
||||
/**
|
||||
* 读取asset目录下文件。
|
||||
* @return content
|
||||
*/
|
||||
public static String readFile(Context mContext,String file,String code)
|
||||
{
|
||||
int len = 0;
|
||||
byte []buf = null;
|
||||
String result = "";
|
||||
try {
|
||||
InputStream in = mContext.getAssets().open(file);
|
||||
len = in.available();
|
||||
buf = new byte[len];
|
||||
in.read(buf, 0, len);
|
||||
|
||||
result = new String(buf,code);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 将字节缓冲区按照固定大小进行分割成数组
|
||||
* @param buffer 缓冲区
|
||||
* @param length 缓冲区大小
|
||||
* @param spsize 切割块大小
|
||||
* @return
|
||||
*/
|
||||
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)
|
||||
return array;
|
||||
int size = 0;
|
||||
while(size < length)
|
||||
{
|
||||
int left = length - size;
|
||||
if(spsize < left)
|
||||
{
|
||||
byte[] sdata = new byte[spsize];
|
||||
System.arraycopy(buffer,size,sdata,0,spsize);
|
||||
array.add(sdata);
|
||||
size += spsize;
|
||||
}else
|
||||
{
|
||||
byte[] sdata = new byte[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: 本地合成资源
|
||||
*/
|
||||
public static String checkLocalResource(){
|
||||
String resource = SpeechUtility.getUtility().getParameter(SpeechConstant.PLUS_LOCAL_ASR);
|
||||
try {
|
||||
JSONObject result = new JSONObject(resource);
|
||||
int ret = result.getInt(SpeechUtility.TAG_RESOURCE_RET);
|
||||
switch (ret) {
|
||||
case ErrorCode.SUCCESS:
|
||||
JSONArray asrArray = result.getJSONObject("result").optJSONArray("asr");
|
||||
if (asrArray != null) {
|
||||
int i = 0;
|
||||
// 查询否包含离线听写资源
|
||||
for (; i < asrArray.length(); i++) {
|
||||
if("iat".equals(asrArray.getJSONObject(i).get(SpeechConstant.DOMAIN))){
|
||||
//asrArray中包含语言、方言字段,后续会增加支持方言的本地听写。
|
||||
//如:"accent": "mandarin","language": "zh_cn"
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= asrArray.length()) {
|
||||
|
||||
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
|
||||
return "没有听写资源,跳转至资源下载页面";
|
||||
}
|
||||
}else {
|
||||
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
|
||||
return "没有听写资源,跳转至资源下载页面";
|
||||
}
|
||||
break;
|
||||
case ErrorCode.ERROR_VERSION_LOWER:
|
||||
return "语记版本过低,请更新后使用本地功能";
|
||||
case ErrorCode.ERROR_INVALID_RESULT:
|
||||
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
|
||||
return "获取结果出错,跳转至资源下载页面";
|
||||
case ErrorCode.ERROR_SYSTEM_PREINSTALL:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SpeechUtility.getUtility().openEngineSettings(SpeechConstant.ENG_ASR);
|
||||
return "获取结果出错,跳转至资源下载页面";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取asset目录下音频文件。
|
||||
*
|
||||
* @return 二进制文件数据
|
||||
*/
|
||||
public static byte[] readAudioFile(Context context, String filename) {
|
||||
try {
|
||||
InputStream ins = context.getAssets().open(filename);
|
||||
byte[] data = new byte[ins.available()];
|
||||
|
||||
ins.read(data);
|
||||
ins.close();
|
||||
|
||||
return data;
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Json结果解析类
|
||||
*/
|
||||
public class JsonParser {
|
||||
|
||||
public static String parseIatResult(String json) {
|
||||
StringBuffer ret = new StringBuffer();
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(json);
|
||||
JSONObject joResult = new JSONObject(tokener);
|
||||
|
||||
JSONArray words = joResult.getJSONArray("ws");
|
||||
for (int i = 0; i < words.length(); i++) {
|
||||
// 转写结果词,默认使用第一个结果
|
||||
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
||||
JSONObject obj = items.getJSONObject(0);
|
||||
ret.append(obj.getString("w"));
|
||||
// 如果需要多候选结果,解析数组其他字段
|
||||
// for(int j = 0; j < items.length(); j++)
|
||||
// {
|
||||
// JSONObject obj = items.getJSONObject(j);
|
||||
// ret.append(obj.getString("w"));
|
||||
// }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String parseGrammarResult(String json) {
|
||||
StringBuffer ret = new StringBuffer();
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(json);
|
||||
JSONObject joResult = new JSONObject(tokener);
|
||||
|
||||
JSONArray words = joResult.getJSONArray("ws");
|
||||
for (int i = 0; i < words.length(); i++) {
|
||||
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
||||
for(int j = 0; j < items.length(); j++)
|
||||
{
|
||||
JSONObject obj = items.getJSONObject(j);
|
||||
if(obj.getString("w").contains("nomatch"))
|
||||
{
|
||||
ret.append("没有匹配结果.");
|
||||
return ret.toString();
|
||||
}
|
||||
ret.append("【结果】" + obj.getString("w"));
|
||||
ret.append("【置信度】" + obj.getInt("sc"));
|
||||
ret.append("\n");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.append("没有匹配结果.");
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String parseLocalGrammarResult(String json) {
|
||||
StringBuffer ret = new StringBuffer();
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(json);
|
||||
JSONObject joResult = new JSONObject(tokener);
|
||||
|
||||
JSONArray words = joResult.getJSONArray("ws");
|
||||
for (int i = 0; i < words.length(); i++) {
|
||||
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
|
||||
for(int j = 0; j < items.length(); j++)
|
||||
{
|
||||
JSONObject obj = items.getJSONObject(j);
|
||||
if(obj.getString("w").contains("nomatch"))
|
||||
{
|
||||
ret.append("没有匹配结果.");
|
||||
return ret.toString();
|
||||
}
|
||||
ret.append("【结果】" + obj.getString("w"));
|
||||
ret.append("\n");
|
||||
}
|
||||
}
|
||||
ret.append("【置信度】" + joResult.optInt("sc"));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret.append("没有匹配结果.");
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String parseTransResult(String json,String key) {
|
||||
StringBuffer ret = new StringBuffer();
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(json);
|
||||
JSONObject joResult = new JSONObject(tokener);
|
||||
String errorCode = joResult.optString("ret");
|
||||
if(!errorCode.equals("0")) {
|
||||
return joResult.optString("errmsg");
|
||||
}
|
||||
JSONObject transResult = joResult.optJSONObject("trans_result");
|
||||
ret.append(transResult.optString(key));
|
||||
/*JSONArray words = joResult.getJSONArray("results");
|
||||
for (int i = 0; i < words.length(); i++) {
|
||||
JSONObject obj = words.getJSONObject(i);
|
||||
ret.append(obj.getString(key));
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ParseResult {
|
||||
/**
|
||||
* 离线人脸框结果解析方法
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
static public FaceRect[] parseResult(String json){
|
||||
FaceRect[] rect = null;
|
||||
if(TextUtils.isEmpty(json)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(json);
|
||||
JSONObject joResult = new JSONObject(tokener);
|
||||
int ret = joResult.optInt("ret");
|
||||
if(ret != 0) {
|
||||
return null;
|
||||
}
|
||||
// 获取每个人脸的结果
|
||||
JSONArray items = joResult.getJSONArray("face");
|
||||
// 获取人脸数目
|
||||
rect = new FaceRect[items.length()];
|
||||
for(int i=0; i<items.length(); i++) {
|
||||
|
||||
JSONObject position = items.getJSONObject(i).getJSONObject("position");
|
||||
// 提取关键点数据
|
||||
rect[i] = new FaceRect();
|
||||
rect[i].bound.left = position.getInt("left");
|
||||
rect[i].bound.top = position.getInt("top");
|
||||
rect[i].bound.right = position.getInt("right");
|
||||
rect[i].bound.bottom = position.getInt("bottom");
|
||||
|
||||
try {
|
||||
JSONObject landmark = items.getJSONObject(i).getJSONObject("landmark");
|
||||
int keyPoint = landmark.length();
|
||||
rect[i].point = new Point[keyPoint];
|
||||
Iterator it = landmark.keys();
|
||||
int point = 0;
|
||||
while (it.hasNext() && point < keyPoint) {
|
||||
String key = (String) it.next();
|
||||
JSONObject postion = landmark.getJSONObject(key);
|
||||
rect[i].point[point] = new Point(postion.getInt("x"), postion.getInt("y"));
|
||||
point++;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import android.content.Context;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* 输入框输入范围控制
|
||||
*/
|
||||
public class SettingTextWatcher implements TextWatcher {
|
||||
private int editStart ;
|
||||
private int editCount ;
|
||||
private EditTextPreference mEditTextPreference;
|
||||
int minValue;//最小值
|
||||
int maxValue;//最大值
|
||||
private Context mContext;
|
||||
|
||||
public SettingTextWatcher(Context context,EditTextPreference e,int min, int max) {
|
||||
mContext = context;
|
||||
mEditTextPreference = e;
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Log.e("demo", "onTextChanged start:"+start+" count:"+count+" before:"+before);
|
||||
editStart = start;
|
||||
editCount = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
|
||||
// Log.e("demo", "beforeTextChanged start:"+start+" count:"+count+" after:"+after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (TextUtils.isEmpty(s)) {
|
||||
return;
|
||||
}
|
||||
String content = s.toString();
|
||||
// Log.e("demo", "content:"+content);
|
||||
if (isNumeric(content)) {
|
||||
int num = Integer.parseInt(content);
|
||||
if (num > maxValue || num < minValue) {
|
||||
s.delete(editStart, editStart+editCount);
|
||||
mEditTextPreference.getEditText().setText(s);
|
||||
Toast.makeText(mContext, "超出有效值范围", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}else {
|
||||
s.delete(editStart, editStart+editCount);
|
||||
mEditTextPreference.getEditText().setText(s);
|
||||
Toast.makeText(mContext, "只能输入数字哦", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则表达式-判断是否为数字
|
||||
*/
|
||||
public static boolean isNumeric(String str){
|
||||
Pattern pattern = Pattern.compile("[0-9]*");
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,57 @@
|
||||
package com.iflytek.speech.util;
|
||||
|
||||
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)
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
try
|
||||
{
|
||||
// DOM builder
|
||||
DocumentBuilder domBuilder = null;
|
||||
// DOM doc
|
||||
Document domDoc = null;
|
||||
|
||||
// init DOM
|
||||
DocumentBuilderFactory domFact = DocumentBuilderFactory.newInstance();
|
||||
domBuilder = domFact.newDocumentBuilder();
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes());
|
||||
domDoc = domBuilder.parse(is);
|
||||
|
||||
// 获取根节点
|
||||
Element root = (Element) domDoc.getDocumentElement();
|
||||
|
||||
Element raw = (Element)root.getElementsByTagName("rawtext").item(0);
|
||||
buffer.append("【识别结果】" + raw.getFirstChild().getNodeValue());
|
||||
buffer.append("\n");
|
||||
|
||||
Element e = (Element)root.getElementsByTagName("result").item(0);
|
||||
|
||||
Element focus = (Element)e.getElementsByTagName("focus").item(0);
|
||||
buffer.append("【FOCUS】" + focus.getFirstChild().getNodeValue());
|
||||
buffer.append("\n");
|
||||
|
||||
Element action = (Element)e.getElementsByTagName("action").item(0);
|
||||
Element operation = (Element)action.getElementsByTagName("operation").item(0);
|
||||
buffer.append("【ACTION】" + operation.getFirstChild().getNodeValue());
|
||||
buffer.append("\n");
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
};
|
||||
buffer.append("【ALL】" + xml);
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,311 @@
|
||||
package com.iflytek.voicedemo;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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;
|
||||
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{
|
||||
private static String TAG = AsrDemo.class.getSimpleName();
|
||||
// 语音识别对象
|
||||
private SpeechRecognizer mAsr;
|
||||
private Toast mToast;
|
||||
// 缓存
|
||||
private SharedPreferences mSharedPreferences;
|
||||
// 云端语法文件
|
||||
private String mCloudGrammar = null;
|
||||
|
||||
private static final String KEY_GRAMMAR_ABNF_ID = "grammar_abnf_id";
|
||||
private static final String GRAMMAR_TYPE_ABNF = "abnf";
|
||||
private static final String GRAMMAR_TYPE_BNF = "bnf";
|
||||
|
||||
private String mEngineType = SpeechConstant.TYPE_CLOUD;
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.isrdemo);
|
||||
initLayout();
|
||||
|
||||
// 初始化识别对象
|
||||
mAsr = SpeechRecognizer.createRecognizer(AsrDemo.this, mInitListener);
|
||||
mCloudGrammar = FucUtil.readFile(this,"grammar_sample.abnf","utf-8");
|
||||
|
||||
mSharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
||||
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化Layout。
|
||||
*/
|
||||
private void initLayout() {
|
||||
findViewById(R.id.isr_recognize).setOnClickListener(AsrDemo.this);
|
||||
findViewById(R.id.isr_grammar).setOnClickListener(AsrDemo.this);
|
||||
findViewById(R.id.isr_stop).setOnClickListener(AsrDemo.this);
|
||||
findViewById(R.id.isr_cancel).setOnClickListener(AsrDemo.this);
|
||||
|
||||
}
|
||||
|
||||
// 语法、词典临时变量
|
||||
String mContent;
|
||||
// 函数调用返回值
|
||||
int ret = 0;
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( null == mAsr ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
if(null == mEngineType) {
|
||||
showTip("请先选择识别引擎类型");
|
||||
return;
|
||||
}
|
||||
switch(view.getId())
|
||||
{
|
||||
case R.id.isr_grammar:
|
||||
showTip("上传预设关键词/语法文件");
|
||||
// 在线-构建语法文件,生成语法id
|
||||
((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");
|
||||
ret = mAsr.buildGrammar(GRAMMAR_TYPE_ABNF, mContent, mCloudGrammarListener);
|
||||
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);// 清空显示内容
|
||||
// 设置参数
|
||||
if (!setParam()) {
|
||||
showTip("请先构建语法。");
|
||||
return;
|
||||
};
|
||||
|
||||
ret = mAsr.startListening(mRecognizerListener);
|
||||
if (ret != ErrorCode.SUCCESS) {
|
||||
showTip("识别失败,错误码: " + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
break;
|
||||
// 停止识别
|
||||
case R.id.isr_stop:
|
||||
mAsr.stopListening();
|
||||
showTip("停止识别");
|
||||
break;
|
||||
// 取消识别
|
||||
case R.id.isr_cancel:
|
||||
mAsr.cancel();
|
||||
showTip("取消识别");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化监听器。
|
||||
*/
|
||||
private InitListener mInitListener = new InitListener() {
|
||||
|
||||
@Override
|
||||
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查询解决方案");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 云端构建语法监听器。
|
||||
*/
|
||||
private GrammarListener mCloudGrammarListener = new GrammarListener() {
|
||||
@Override
|
||||
public void onBuildFinish(String grammarId, SpeechError error) {
|
||||
if(error == null){
|
||||
String grammarID = new String(grammarId);
|
||||
Editor editor = mSharedPreferences.edit();
|
||||
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查询解决方案");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 识别监听器。
|
||||
*/
|
||||
private RecognizerListener mRecognizerListener = new RecognizerListener() {
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(int volume, byte[] data) {
|
||||
showTip("当前正在说话,音量大小:" + volume);
|
||||
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)){
|
||||
text = JsonParser.parseGrammarResult(result.getResultString());
|
||||
}else {
|
||||
text = JsonParser.parseLocalGrammarResult(result.getResultString());
|
||||
}
|
||||
|
||||
// 显示
|
||||
((EditText)findViewById(R.id.isr_text)).setText(text);
|
||||
} else {
|
||||
Log.d(TAG, "recognizer result : null");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndOfSpeech() {
|
||||
// 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入
|
||||
showTip("结束说话");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeginOfSpeech() {
|
||||
// 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入
|
||||
showTip("开始说话");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
showTip("onError Code:" + error.getErrorCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
|
||||
// 若使用本地能力,会话id为null
|
||||
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
|
||||
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
||||
// Log.d(TAG, "session id =" + sid);
|
||||
// }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
private void showTip(final String str) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数设置
|
||||
* @return
|
||||
*/
|
||||
public boolean setParam(){
|
||||
boolean result = false;
|
||||
//设置识别引擎
|
||||
mAsr.setParameter(SpeechConstant.ENGINE_TYPE, mEngineType);
|
||||
//设置返回结果为json格式
|
||||
mAsr.setParameter(SpeechConstant.RESULT_TYPE, "json");
|
||||
|
||||
if("cloud".equalsIgnoreCase(mEngineType))
|
||||
{
|
||||
String grammarId = mSharedPreferences.getString(KEY_GRAMMAR_ABNF_ID, null);
|
||||
if(TextUtils.isEmpty(grammarId))
|
||||
{
|
||||
result = false;
|
||||
}else {
|
||||
//设置云端识别使用的语法id
|
||||
mAsr.setParameter(SpeechConstant.CLOUD_GRAMMAR, grammarId);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
||||
mAsr.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
|
||||
mAsr.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/asr.wav");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,524 @@
|
||||
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;
|
||||
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;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iflytek.cloud.ErrorCode;
|
||||
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;
|
||||
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;*/
|
||||
|
||||
public class IatDemo extends Activity implements OnClickListener {
|
||||
private static String TAG = IatDemo.class.getSimpleName();
|
||||
// 语音听写对象
|
||||
private SpeechRecognizer mIat;
|
||||
// 语音听写UI
|
||||
private RecognizerDialog mIatDialog;
|
||||
// 用HashMap存储听写结果
|
||||
private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
|
||||
|
||||
private EditText mResultText;
|
||||
private EditText showContacts;
|
||||
private TextView languageText;
|
||||
private Toast mToast;
|
||||
private SharedPreferences mSharedPreferences;
|
||||
// 引擎类型
|
||||
private String mEngineType = SpeechConstant.TYPE_CLOUD;
|
||||
|
||||
private String[] languageEntries ;
|
||||
private String[] languageValues;
|
||||
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);
|
||||
setContentView(R.layout.iatdemo);
|
||||
|
||||
languageEntries = getResources().getStringArray(R.array.iat_language_entries);
|
||||
languageValues = getResources().getStringArray(R.array.iat_language_value);
|
||||
initLayout();
|
||||
// 初始化识别无UI识别对象
|
||||
// 使用SpeechRecognizer对象,可根据回调消息自定义界面;
|
||||
mIat = SpeechRecognizer.createRecognizer(IatDemo.this, mInitListener);
|
||||
|
||||
// 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer
|
||||
// 使用UI听写功能,请根据sdk文件目录下的notice.txt,放置布局文件和图片资源
|
||||
mIatDialog = new RecognizerDialog(IatDemo.this, mInitListener);
|
||||
|
||||
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);
|
||||
findViewById(R.id.image_iat_set).setOnClickListener(IatDemo.this);
|
||||
findViewById(R.id.languageText).setOnClickListener(IatDemo.this);
|
||||
}
|
||||
|
||||
int ret = 0; // 函数调用返回值
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( null == mIat ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
// 进入参数设置页面
|
||||
case R.id.image_iat_set:
|
||||
Intent intents = new Intent(IatDemo.this, IatSettings.class);
|
||||
startActivity(intents);
|
||||
break;
|
||||
// 开始听写
|
||||
// 如何判断一次听写结束:OnResult isLast=true 或者 onError
|
||||
case R.id.iat_recognize:
|
||||
// 移动数据分析,收集开始听写事件
|
||||
// FlowerCollector.onEvent(IatDemo.this, "iat_recognize");
|
||||
|
||||
buffer.setLength(0);
|
||||
mResultText.setText(null);// 清空显示内容
|
||||
mIatResults.clear();
|
||||
// 设置参数
|
||||
setParam();
|
||||
boolean isShowDialog = mSharedPreferences.getBoolean(
|
||||
getString(R.string.pref_key_iat_show), true);
|
||||
if (isShowDialog) {
|
||||
// 显示听写对话框
|
||||
mIatDialog.setListener(mRecognizerDialogListener);
|
||||
mIatDialog.show();
|
||||
showTip(getString(R.string.text_begin));
|
||||
} else {
|
||||
// 不显示听写对话框
|
||||
ret = mIat.startListening(mRecognizerListener);
|
||||
if (ret != ErrorCode.SUCCESS) {
|
||||
showTip("听写失败,错误码:" + ret+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
} else {
|
||||
showTip(getString(R.string.text_begin));
|
||||
}
|
||||
}
|
||||
break;
|
||||
// 音频流识别
|
||||
case R.id.iat_recognize_stream:
|
||||
executeStream();
|
||||
break;
|
||||
case R.id.languageText:
|
||||
setLanguage(view);
|
||||
break;
|
||||
// 停止听写
|
||||
case R.id.iat_stop:
|
||||
mIat.stopListening();
|
||||
showTip("停止听写");
|
||||
break;
|
||||
// 取消听写
|
||||
case R.id.iat_cancel:
|
||||
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");
|
||||
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查询解决方案");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化监听器。
|
||||
*/
|
||||
private InitListener mInitListener = new InitListener() {
|
||||
|
||||
@Override
|
||||
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查询解决方案");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 在线听写支持多种小语种设置。支持语言类型如下:
|
||||
* <item>zh_cn</item> 中文
|
||||
* <item>en_us</item> 英文
|
||||
* <item>ja_jp</item> 日语
|
||||
* <item>ru-ru</item> 俄语
|
||||
* <item>es_es</item> 西班牙语
|
||||
* <item>fr_fr</item> 法语
|
||||
* <item>ko_kr</item> 韩语
|
||||
* @param v
|
||||
*/
|
||||
private void setLanguage(View v){
|
||||
new AlertDialog.Builder(v.getContext()).setTitle("语种语言种类")
|
||||
.setSingleChoiceItems(languageEntries, // 单选框有几项,各是什么名字
|
||||
0, // 默认的选项
|
||||
new DialogInterface.OnClickListener() { // 点击单选框后的处理
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) { // 点击了哪一项
|
||||
language = languageValues[which];
|
||||
((TextView)findViewById(R.id.languageText)).setText("你选择的是:"+languageEntries[which]);
|
||||
selectedNum = which;
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).show();
|
||||
mIat.setParameter(SpeechConstant.LANGUAGE, language);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传联系人/词表监听器。
|
||||
*/
|
||||
private LexiconListener mLexiconListener = new LexiconListener() {
|
||||
|
||||
@Override
|
||||
public void onLexiconUpdated(String lexiconId, SpeechError error) {
|
||||
if (error != null) {
|
||||
showTip(error.toString());
|
||||
} else {
|
||||
showTip(getString(R.string.text_upload_success));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 听写监听器。
|
||||
*/
|
||||
private RecognizerListener mRecognizerListener = new RecognizerListener() {
|
||||
|
||||
@Override
|
||||
public void onBeginOfSpeech() {
|
||||
// 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入
|
||||
showTip("开始说话");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
// Tips:
|
||||
// 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。
|
||||
|
||||
showTip(error.getPlainDescription(true));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndOfSpeech() {
|
||||
// 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入
|
||||
showTip("结束说话");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(RecognizerResult results, boolean isLast) {
|
||||
Log.d(TAG, results.getResultString());
|
||||
System.out.println(flg++);
|
||||
if (resultType.equals("json")) {
|
||||
|
||||
printResult(results);
|
||||
|
||||
}else 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
|
||||
// 若使用本地能力,会话id为null
|
||||
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
|
||||
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
||||
// Log.d(TAG, "session id =" + sid);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
private void printResult(RecognizerResult results) {
|
||||
String text = JsonParser.parseIatResult(results.getResultString());
|
||||
|
||||
String sn = null;
|
||||
// 读取json结果中的sn字段
|
||||
try {
|
||||
JSONObject resultJson = new JSONObject(results.getResultString());
|
||||
sn = resultJson.optString("sn");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mIatResults.put(sn, text);
|
||||
|
||||
StringBuffer resultBuffer = new StringBuffer();
|
||||
for (String key : mIatResults.keySet()) {
|
||||
resultBuffer.append(mIatResults.get(key));
|
||||
}
|
||||
|
||||
mResultText.setText(resultBuffer.toString());
|
||||
mResultText.setSelection(mResultText.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* 听写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);
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数设置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
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")) {
|
||||
String lag = mSharedPreferences.getString("iat_language_preference",
|
||||
"mandarin");
|
||||
Log.e(TAG,"language:"+language);// 设置语言
|
||||
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
|
||||
// 设置语言区域
|
||||
mIat.setParameter(SpeechConstant.ACCENT, lag);
|
||||
}else {
|
||||
|
||||
mIat.setParameter(SpeechConstant.LANGUAGE, language);
|
||||
}
|
||||
Log.e(TAG,"last language:"+mIat.getParameter(SpeechConstant.LANGUAGE));
|
||||
|
||||
//此处用于设置dialog中不显示错误码信息
|
||||
//mIat.setParameter("view_tips_plain","false");
|
||||
|
||||
// 设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理
|
||||
mIat.setParameter(SpeechConstant.VAD_BOS, mSharedPreferences.getString("iat_vadbos_preference", "4000"));
|
||||
|
||||
// 设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 自动停止录音
|
||||
mIat.setParameter(SpeechConstant.VAD_EOS, mSharedPreferences.getString("iat_vadeos_preference", "1000"));
|
||||
|
||||
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
|
||||
mIat.setParameter(SpeechConstant.ASR_PTT, mSharedPreferences.getString("iat_punc_preference", "1"));
|
||||
|
||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
||||
mIat.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
|
||||
mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/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);// 清空显示内容
|
||||
mIatResults.clear();
|
||||
// 设置参数
|
||||
setParam();
|
||||
// 设置音频来源为外部文件
|
||||
mIat.setParameter(SpeechConstant.AUDIO_SOURCE, "-1");
|
||||
// 也可以像以下这样直接设置音频文件路径识别(要求设置文件在sdcard上的全路径):
|
||||
// mIat.setParameter(SpeechConstant.AUDIO_SOURCE, "-2");
|
||||
//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){
|
||||
|
||||
}
|
||||
}
|
||||
mIat.stopListening();
|
||||
/*mIat.writeAudio(audioData, 0, audioData.length );
|
||||
mIat.stopListening();*/
|
||||
} else {
|
||||
mIat.cancel();
|
||||
showTip("读取音频流失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,470 @@
|
||||
package com.iflytek.voicedemo.IdentifyGroup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
import android.graphics.Matrix;
|
||||
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;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iflytek.cloud.ErrorCode;
|
||||
import com.iflytek.cloud.IdentityListener;
|
||||
import com.iflytek.cloud.IdentityResult;
|
||||
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;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 人脸验证示例demo
|
||||
*
|
||||
* @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();
|
||||
|
||||
// 用户输入的组ID
|
||||
private String mGroupId;
|
||||
// 身份鉴别对象
|
||||
private IdentityVerifier mIdVerifier;
|
||||
|
||||
private TextView txt_groupid;
|
||||
private ProgressDialog mProDialog;
|
||||
private Toast mToast;
|
||||
|
||||
// 选择图片后返回
|
||||
public static final int REQUEST_PICTURE_CHOOSE = 1;
|
||||
// 拍照后返回
|
||||
private final static int REQUEST_CAMERA_IMAGE = 2;
|
||||
// 裁剪图片成功后返回
|
||||
public static final int REQUEST_INTENT_CROP = 3;
|
||||
|
||||
private Bitmap mImageBitmap = null;
|
||||
private byte[] mImageData = null;
|
||||
private File mPictureFile;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_face_identify);
|
||||
|
||||
// 身份验证对象初始化
|
||||
mGroupId = getIntent().getStringExtra("group_id");
|
||||
// 对象初始化监听器
|
||||
mIdVerifier = IdentityVerifier.createVerifier(FaceIdentifyActivity.this, new InitListener() {
|
||||
@Override
|
||||
public void onInit(int errorCode) {
|
||||
if (ErrorCode.SUCCESS == errorCode) {
|
||||
showTip("引擎初始化成功");
|
||||
} else {
|
||||
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化界面
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
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);
|
||||
mProDialog = new ProgressDialog(FaceIdentifyActivity.this);
|
||||
mProDialog.setCancelable(true);
|
||||
mProDialog.setTitle("请稍候");
|
||||
// cancel进度框时,取消正在进行的操作
|
||||
mProDialog.setOnCancelListener(new OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mToast = Toast.makeText(FaceIdentifyActivity.this, "", Toast.LENGTH_SHORT);
|
||||
mToast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||
|
||||
txt_groupid.setText(mGroupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人脸鉴别监听器
|
||||
*/
|
||||
private IdentityListener mSearchListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
dismissProDialog();
|
||||
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
dismissProDialog();
|
||||
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( null == mIdVerifier ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
case R.id.online_pick:
|
||||
// 调用系统相册,完成选图
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_PICK);
|
||||
startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
|
||||
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);
|
||||
break;
|
||||
|
||||
case R.id.btn_identity:
|
||||
if (null != mImageData) {
|
||||
mProDialog.setMessage("鉴别中...");
|
||||
mProDialog.show();
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置业务场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ifr");
|
||||
// 设置业务类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "identify");
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mSearchListener);
|
||||
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
params.append(",group_id=" + mGroupId +",topc=3");
|
||||
// 向子业务写入数据,人脸数据可以一次写入
|
||||
mIdVerifier.writeData("ifr", params.toString(), mImageData, 0, mImageData.length);
|
||||
// 写入完毕
|
||||
mIdVerifier.stopWrite("ifr");
|
||||
} else {
|
||||
showTip("请选择图片后再鉴别");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleResult(IdentityResult result) {
|
||||
if (null == result) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String resultStr = result.getResultString();
|
||||
JSONObject resultJson = new JSONObject(resultStr);
|
||||
if(ErrorCode.SUCCESS == resultJson.getInt("ret"))
|
||||
{
|
||||
// 跳转到结果展示页面
|
||||
Intent intent = new Intent(FaceIdentifyActivity.this, ResultIdentifyActivity.class);
|
||||
intent.putExtra("result", resultStr);
|
||||
startActivity(intent);
|
||||
this.finish();
|
||||
}
|
||||
else {
|
||||
showTip("鉴别失败!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
// 跳转到图片裁剪页面
|
||||
cropPicture(this,Uri.fromFile(new File(fileSrc)));
|
||||
} else if (requestCode == REQUEST_CAMERA_IMAGE) {
|
||||
if (null == mPictureFile) {
|
||||
showTip("拍照失败,请重试");
|
||||
return;
|
||||
}
|
||||
|
||||
fileSrc = mPictureFile.getAbsolutePath();
|
||||
updateGallery(fileSrc);
|
||||
// 跳转到图片裁剪页面
|
||||
cropPicture(this,Uri.fromFile(new File(fileSrc)));
|
||||
} else if (requestCode == REQUEST_INTENT_CROP) {
|
||||
|
||||
// 获取返回数据
|
||||
Bitmap bmp = data.getParcelableExtra("data");
|
||||
|
||||
// 获取裁剪后图片保存路径
|
||||
fileSrc = getImagePath();
|
||||
|
||||
// 若返回数据不为null,保存至本地,防止裁剪时未能正常保存
|
||||
if(null != bmp){
|
||||
saveBitmapToFile(bmp);
|
||||
}
|
||||
|
||||
// 获取图片的宽和高
|
||||
Options options = new Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
mImageBitmap = BitmapFactory.decodeFile(fileSrc, options);
|
||||
|
||||
// 压缩图片
|
||||
options.inSampleSize = Math.max(1, (int) Math.ceil(Math.max(
|
||||
(double) options.outWidth / 1024f,
|
||||
(double) options.outHeight / 1024f)));
|
||||
options.inJustDecodeBounds = false;
|
||||
mImageBitmap = BitmapFactory.decodeFile(fileSrc, options);
|
||||
|
||||
// 若mImageBitmap为空则图片信息不能正常获取
|
||||
if(null == mImageBitmap) {
|
||||
showTip("图片信息无法正常获取!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 部分手机会对图片做旋转,这里检测旋转角度
|
||||
int degree = readPictureDegree(fileSrc);
|
||||
if (degree != 0) {
|
||||
// 把图片旋转为正的方向
|
||||
mImageBitmap = rotateImage(degree, mImageBitmap);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
//可根据流量及网络状况对图片进行压缩
|
||||
mImageBitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos);
|
||||
mImageData = baos.toByteArray();
|
||||
|
||||
((ImageView) findViewById(R.id.online_img)).setImageBitmap(mImageBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
setResult(RESULT_OK);
|
||||
super.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.destroy();
|
||||
mIdVerifier = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取图片属性:旋转的角度
|
||||
*
|
||||
* @param path 图片绝对路径
|
||||
* @return degree 旋转的角度
|
||||
*/
|
||||
public static int readPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
private void updateGallery(String filename) {
|
||||
MediaScannerConnection.scanFile(this, new String[] {filename}, null,
|
||||
new MediaScannerConnection.OnScanCompletedListener() {
|
||||
|
||||
@Override
|
||||
public void onScanCompleted(String path, Uri uri) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 旋转图片
|
||||
*
|
||||
* @param angle
|
||||
* @param bitmap
|
||||
* @return Bitmap
|
||||
*/
|
||||
public static Bitmap rotateImage(int angle, Bitmap bitmap) {
|
||||
// 图片旋转矩阵
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(angle);
|
||||
// 得到旋转后的图片
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
|
||||
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
return resizedBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toast弹出提示
|
||||
* @param str
|
||||
*/
|
||||
private void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 裁剪图片
|
||||
* @param activity Activity
|
||||
* @param uri 图片的Uri
|
||||
*/
|
||||
public void cropPicture(Activity activity, Uri uri) {
|
||||
Intent innerIntent = new Intent("com.android.camera.action.CROP");
|
||||
innerIntent.setDataAndType(uri, "image/*");
|
||||
innerIntent.putExtra("crop", "true");// 才能出剪辑的小方框,不然没有剪辑功能,只能选取图片
|
||||
innerIntent.putExtra("aspectX", 1); // 放大缩小比例的X
|
||||
innerIntent.putExtra("aspectY", 1);// 放大缩小比例的X 这里的比例为: 1:1
|
||||
innerIntent.putExtra("outputX", 320); //这个是限制输出图片大小
|
||||
innerIntent.putExtra("outputY", 320);
|
||||
innerIntent.putExtra("return-data", true);
|
||||
// 切图大小不足输出,无黑框
|
||||
innerIntent.putExtra("scale", true);
|
||||
innerIntent.putExtra("scaleUpIfNeeded", true);
|
||||
innerIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(getImagePath())));
|
||||
innerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
|
||||
activity.startActivityForResult(innerIntent, REQUEST_INTENT_CROP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置保存图片路径
|
||||
* @return
|
||||
*/
|
||||
private String getImagePath(){
|
||||
String path;
|
||||
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
return null;
|
||||
}
|
||||
path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/MFVDemo/";
|
||||
File folder = new File(path);
|
||||
if (folder != null && !folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
path += "mfvtest.jpg";
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存Bitmap至本地
|
||||
* @param bmp
|
||||
*/
|
||||
private void saveBitmapToFile(Bitmap bmp){
|
||||
String file_path = getImagePath();
|
||||
File file = new File(file_path);
|
||||
FileOutputStream fOut;
|
||||
try {
|
||||
fOut = new FileOutputStream(file);
|
||||
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void dismissProDialog() {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,536 @@
|
||||
package com.iflytek.voicedemo.IdentifyGroup;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
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.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iflytek.cloud.IdentityListener;
|
||||
import com.iflytek.cloud.IdentityResult;
|
||||
import com.iflytek.cloud.IdentityVerifier;
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
import com.iflytek.cloud.SpeechError;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 声纹密码和人脸识别相关组操作
|
||||
* 支持组创建/添加成员/查询组成员/删除成员/删除组/
|
||||
* @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 {
|
||||
private final static String TAG = GroupManagerActivity.class.getSimpleName();
|
||||
// 身份验证对象
|
||||
private IdentityVerifier mIdVerifier;
|
||||
// 用户名信息
|
||||
private TextView mUserNameText;
|
||||
|
||||
EditText etGroupId;
|
||||
EditText etGroupName;
|
||||
private Toast mToast;
|
||||
MyAdapter adapter;
|
||||
private ProgressDialog mProDialog;
|
||||
String authId;
|
||||
String mfv_type;
|
||||
ArrayList<Map<String,String>> mList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_group_manager);
|
||||
mIdVerifier = IdentityVerifier.createVerifier(this, null);
|
||||
|
||||
authId = getIntent().getStringExtra("auth_id");
|
||||
mfv_type = getIntent().getStringExtra("mfv_scenes");
|
||||
mList = new ArrayList<Map<String, String>>();
|
||||
// 画面初期化
|
||||
initLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* 画面初期化。
|
||||
*/
|
||||
@SuppressLint("ShowToast")
|
||||
private void initLayout() {
|
||||
|
||||
mProDialog = new ProgressDialog(this);
|
||||
// 等待框设置为不可取消
|
||||
mProDialog.setCancelable(true);
|
||||
mProDialog.setCanceledOnTouchOutside(false);
|
||||
mProDialog.setTitle("请稍候");
|
||||
|
||||
mProDialog.setOnCancelListener(new OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
// cancel进度框时,取消正在进行的操作
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.group_header_layout, null);
|
||||
|
||||
mUserNameText = (TextView) view.findViewById(R.id.txt_username);
|
||||
mUserNameText.setText(authId);
|
||||
|
||||
stopProgress();
|
||||
// 创建组
|
||||
((Button) view.findViewById(R.id.btn_group_create)).setOnClickListener(this);
|
||||
// 加入组
|
||||
((Button) view.findViewById(R.id.btn_group_join)).setOnClickListener(this);
|
||||
|
||||
((Button) view.findViewById(R.id.btn_person_delete)).setOnClickListener(this);
|
||||
((Button) view.findViewById(R.id.btn_group_delete)).setOnClickListener(this);
|
||||
// 输入组id
|
||||
etGroupId = ((EditText) view.findViewById(R.id.edt_group_id));
|
||||
// 输入组名称
|
||||
etGroupName = ((EditText) view.findViewById(R.id.edt_group_name));
|
||||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
|
||||
|
||||
// 绑定XML中的ListView,作为Item的容器
|
||||
ListView list = (ListView) findViewById(R.id.lv_my_group);
|
||||
list.setOnItemClickListener(this);
|
||||
list.addHeaderView(view);
|
||||
// 去除行与行之间的黑线:
|
||||
list.setDivider(null);
|
||||
|
||||
// 添加并且显示
|
||||
adapter = new MyAdapter(this, mList );
|
||||
list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( null == mIdVerifier ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.btn_group_create:
|
||||
createGroup();
|
||||
break;
|
||||
case R.id.btn_group_join:
|
||||
joinGroup(null);
|
||||
break;
|
||||
case R.id.btn_person_delete:
|
||||
deleteGroup(null, false);
|
||||
break;
|
||||
case R.id.btn_group_delete:
|
||||
deleteGroup(null, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
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);
|
||||
}
|
||||
startActivity(init);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启进度条
|
||||
*/
|
||||
private void startProgress(String msg) {
|
||||
mProDialog.setMessage(msg);
|
||||
mProDialog.show();
|
||||
((RelativeLayout) findViewById(R.id.group_manager_layout)).setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭进度条
|
||||
*/
|
||||
private void stopProgress() {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
((RelativeLayout) findViewById(R.id.group_manager_layout)).setEnabled(true);
|
||||
}
|
||||
|
||||
private void createGroup() {
|
||||
String groupName = etGroupName.getText().toString();
|
||||
if (TextUtils.isEmpty(groupName)) {
|
||||
showTip("请填写groupName");
|
||||
return;
|
||||
}
|
||||
startProgress("正在创建组...");
|
||||
// sst=add,scope=group,group_name=famil;
|
||||
// 设置人脸模型操作参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ipt");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authId);
|
||||
|
||||
// 设置模型参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
params.append("auth_id=" + authId);
|
||||
params.append(",scope=group");
|
||||
params.append(",group_name=" + groupName);
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ipt", "add", params.toString(), mCreateListener);
|
||||
}
|
||||
|
||||
private void joinGroup(String groupIdCreate) {
|
||||
String groupId;
|
||||
if (!TextUtils.isEmpty(groupIdCreate)) {
|
||||
groupId = groupIdCreate;
|
||||
} else {
|
||||
groupId = etGroupId.getText().toString();
|
||||
}
|
||||
if (TextUtils.isEmpty(groupId)) {
|
||||
showTip("请填写groupId");
|
||||
return;
|
||||
}
|
||||
startProgress("正在加入组...");
|
||||
|
||||
// sst=add,auth_id=eqhe,group_id=123456,scope=person
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ipt");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authId);
|
||||
// 设置模型参数,若无可以传空字符传
|
||||
StringBuffer params2 = new StringBuffer();
|
||||
params2.append("auth_id=" + authId);
|
||||
params2.append(",scope=person");
|
||||
params2.append(",group_id=" + groupId);
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ipt", "add", params2.toString(), mAddListener);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询指定组中成员
|
||||
// * @param groupJoin
|
||||
// */
|
||||
// private void queryGroup(String groupJoin) {
|
||||
// String groupId;
|
||||
// if (!TextUtils.isEmpty(groupJoin)) {
|
||||
// groupId = groupJoin;
|
||||
// } else {
|
||||
// groupId = etGroupId.getText().toString();
|
||||
// }
|
||||
// if (TextUtils.isEmpty(groupId)) {
|
||||
// showTip("请填写groupId");
|
||||
// return;
|
||||
// }
|
||||
// startProgress("正在查询组成员...");
|
||||
//
|
||||
// // sst=add,auth_id=eqhe,group_id=123456,scope=person
|
||||
// mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// // 设置会话场景
|
||||
// mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ipt");
|
||||
// // 用户id
|
||||
// mIdVerifier.setParameter(SpeechConstant.AUTH_ID, DemoApp.getHostUser().getUsername());
|
||||
// // 设置模型参数,若无可以传空字符传
|
||||
// StringBuffer params2 = new StringBuffer();
|
||||
// params2.append("scope=group");
|
||||
// params2.append(",group_id=" + groupId);
|
||||
// // 执行模型操作
|
||||
// mIdVerifier.execute("ipt", "query", params2.toString(), mQueryListener);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 查询当前appid 下所有组
|
||||
// * 此处特别申明:***查询所有组信息能力仅提供用于开发者debug所用,如果用于其他
|
||||
// * 场景或者处于其他目的,责任由程序开发者自付***
|
||||
// */
|
||||
/*
|
||||
private void queryGroups() {
|
||||
startProgress("正在查询组数量...");
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, "wer");
|
||||
// 设置模型参数,若无可以传空字符传
|
||||
StringBuffer params2 = new StringBuffer();
|
||||
params2.append("scope=appid");
|
||||
Log.e(TAG,"queryGroups:"+params2.toString());
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ipt", "query", params2.toString(), mQueryListener);
|
||||
}*/
|
||||
|
||||
private void deleteGroup(String groupJoin, boolean deleteGroup) {
|
||||
String groupId;
|
||||
if (!TextUtils.isEmpty(groupJoin)) {
|
||||
groupId = groupJoin;
|
||||
} else {
|
||||
groupId = etGroupId.getText().toString();
|
||||
}
|
||||
if (TextUtils.isEmpty(groupId)) {
|
||||
showTip("请填写groupId");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
startProgress("正在删除...");
|
||||
|
||||
// sst=add,auth_id=eqhe,group_id=123456,scope=person
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ipt");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authId);
|
||||
|
||||
// 设置模型参数,若无可以传空字符传
|
||||
StringBuffer params2 = new StringBuffer();
|
||||
if(deleteGroup) {
|
||||
params2.append("scope=group");
|
||||
} else {
|
||||
// 删除组中指定auth_id用户
|
||||
params2.append("scope=person");
|
||||
params2.append(",auth_id="+authId);
|
||||
}
|
||||
params2.append(",group_id=" + groupId);
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ipt", "delete", params2.toString(), mDeleteListener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建组监听器
|
||||
*/
|
||||
private IdentityListener mCreateListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
stopProgress();
|
||||
Log.d(TAG, result.getResultString());
|
||||
try {
|
||||
JSONObject resObj = new JSONObject(result.getResultString());
|
||||
resObj.getString("group_id");
|
||||
// 创建成功后将自己加入到组里
|
||||
joinGroup(resObj.getString("group_id"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
showTip("组创建成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
stopProgress();
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 加入组监听器
|
||||
*/
|
||||
private IdentityListener mAddListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
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"));
|
||||
synchronized (mList) {
|
||||
if (mList != null && mList.size() >0) {
|
||||
for(int i = 0;i<mList.size();i++) {
|
||||
if(!mList.contains(map)) {
|
||||
mList.add(map);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
mList.add(map);
|
||||
}
|
||||
mList.notify();
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
showTip("加入组成功");
|
||||
//adapter.setArray(mList);
|
||||
adapter.notifyDataSetChanged();
|
||||
stopProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
stopProgress();
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
};
|
||||
|
||||
private IdentityListener mQueryListener = new IdentityListener() {
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
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));
|
||||
//showTip(ErrorDesc.getDesc(error) + ":" + error.getErrorCode());
|
||||
stopProgress();
|
||||
}
|
||||
};
|
||||
|
||||
private IdentityListener mDeleteListener = new IdentityListener() {
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
try {
|
||||
JSONObject resObj = new JSONObject(result.getResultString());
|
||||
Log.d(TAG,"resObj == "+resObj.toString());
|
||||
int ret = resObj.getInt("ret");
|
||||
if(0 != ret) {
|
||||
onError(new SpeechError(ret));
|
||||
return;
|
||||
} else {
|
||||
if(result.getResultString().contains("user")) {
|
||||
String user = resObj.getString("user");
|
||||
showTip("删除组成员"+user+"成功");
|
||||
} else {
|
||||
showTip("删除组成功");
|
||||
// 保存到用户信息中,用来显示用户加人的组
|
||||
for (Map<String,String> map1:mList){
|
||||
if (map1.get("group_id").equals(resObj.getString("group_id"))){
|
||||
mList.remove(map1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
adapter.setArray(mList);
|
||||
adapter.notifyDataSetChanged();
|
||||
stopProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
stopProgress();
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
};
|
||||
|
||||
private void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
private class MyAdapter extends BaseAdapter {
|
||||
|
||||
private Context context;
|
||||
private LayoutInflater inflater;
|
||||
public ArrayList<Map<String,String>> arr;
|
||||
|
||||
public MyAdapter(Context context, ArrayList<Map<String,String>> array) {
|
||||
super();
|
||||
this.context = context;
|
||||
inflater = LayoutInflater.from(context);
|
||||
arr = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (arr != null)
|
||||
return arr.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int arg0) {
|
||||
if (arr.get(arg0) != null) {
|
||||
return arr.get(arg0);
|
||||
}
|
||||
return arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int arg0) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
public void setArray(ArrayList<Map<String,String>> list) {
|
||||
this.arr = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
if (view == null) {
|
||||
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的时候不至于数据错乱
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package com.iflytek.voicedemo.IdentifyGroup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* 1:N检测结果解析界面
|
||||
* @author hjyu
|
||||
* @date 2017/9/28.
|
||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||
*/
|
||||
public class ResultIdentifyActivity extends Activity implements OnClickListener {
|
||||
|
||||
private String result;
|
||||
JSONArray candidates;
|
||||
MyAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_result_identify);
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
TextView title = (TextView) findViewById(R.id.txt_idf_result_title);
|
||||
|
||||
result = getIntent().getStringExtra("result");
|
||||
// 结果形式
|
||||
// result = "
|
||||
/*{
|
||||
"ret":0,
|
||||
"group_id":"xxxxxx",
|
||||
"group_name":"xxxxxx",
|
||||
"ifv_result":{
|
||||
"candidates":[{
|
||||
"model_id":"xxxxxxxx",
|
||||
"decision":"accepted",
|
||||
"score":88.888888,
|
||||
"user":"user_name"}]
|
||||
},
|
||||
"sst":"identify",
|
||||
"ssub":"ivp",
|
||||
"topc":1
|
||||
}*/
|
||||
try {
|
||||
JSONObject obj = new JSONObject(result);
|
||||
// 组名称
|
||||
((TextView)findViewById(R.id.txt_group_name)).setText(obj.getString("group_name"));
|
||||
|
||||
JSONObject ifv_result = obj.getJSONObject("ifv_result");
|
||||
candidates = ifv_result.getJSONArray("candidates");
|
||||
|
||||
// 鉴别结果
|
||||
// 绑定XML中的ListView,作为Item的容器
|
||||
ListView list = (ListView) findViewById(R.id.lv_identify_result);
|
||||
// 去除行与行之间的黑线:
|
||||
list.setDivider(null);
|
||||
// 添加并且显示
|
||||
adapter = new MyAdapter(ResultIdentifyActivity.this, candidates);
|
||||
list.setAdapter(adapter);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 相似度排行
|
||||
private class MyAdapter extends BaseAdapter {
|
||||
|
||||
private LayoutInflater inflater;
|
||||
public JSONArray arr;
|
||||
|
||||
public MyAdapter(Context context, JSONArray array) {
|
||||
super();
|
||||
inflater = LayoutInflater.from(context);
|
||||
arr = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (arr != null)
|
||||
return arr.length();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int arg0) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int arg0) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
if (view == null) {
|
||||
view = inflater.inflate(R.layout.item_identify_result, null);
|
||||
}
|
||||
final TextView tx_number = (TextView) view.findViewById(R.id.identify_item_number);
|
||||
final TextView tx_user = (TextView) view.findViewById(R.id.identify_item_user);
|
||||
final TextView tx_score = (TextView) view.findViewById(R.id.identify_item_score);
|
||||
JSONObject obj;
|
||||
try {
|
||||
obj = arr.getJSONObject(position);
|
||||
tx_number.setText("第" + getChineseNumber(position + 1) + ":");
|
||||
tx_user.setText(obj.optString("user"));
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
Double score = obj.optDouble("score");
|
||||
String scoreStr = df.format(score) + "%";
|
||||
tx_score.setText(scoreStr);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
private String getChineseNumber(int number) {
|
||||
String[] str = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
|
||||
String ss[] = new String[] { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" };
|
||||
String s = String.valueOf(number);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
String index = String.valueOf(s.charAt(i));
|
||||
sb = sb.append(str[Integer.parseInt(index)]);
|
||||
}
|
||||
String sss = String.valueOf(sb);
|
||||
int i = 0;
|
||||
for (int j = sss.length(); j > 0; j--) {
|
||||
sb = sb.insert(j, ss[i++]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
}
|
||||
}
|
@ -0,0 +1,334 @@
|
||||
package com.iflytek.voicedemo.IdentifyGroup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iflytek.cloud.ErrorCode;
|
||||
import com.iflytek.cloud.IdentityListener;
|
||||
import com.iflytek.cloud.IdentityResult;
|
||||
import com.iflytek.cloud.IdentityVerifier;
|
||||
import com.iflytek.cloud.InitListener;
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
import com.iflytek.cloud.SpeechError;
|
||||
import com.iflytek.cloud.SpeechEvent;
|
||||
import com.iflytek.cloud.record.PcmRecorder;
|
||||
import com.iflytek.cloud.record.PcmRecorder.PcmRecordListener;
|
||||
import com.iflytek.cloud.util.VerifierUtil;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* 声纹鉴别页面
|
||||
*
|
||||
* @author hjyu
|
||||
* @date 2017/9/28.
|
||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||
* */
|
||||
public class VocalIdentifyActivity extends Activity implements OnClickListener {
|
||||
private static final String TAG = VocalIdentifyActivity.class.getSimpleName();
|
||||
|
||||
// 密码类型
|
||||
// 默认为数字密码
|
||||
private int mPwdType = 3;
|
||||
// 用于鉴别的数字密码
|
||||
private String mIdentifyNumPwd = "";
|
||||
|
||||
// 用户输入的组ID
|
||||
private String mGroupId;
|
||||
// 身份鉴别对象
|
||||
private IdentityVerifier mIdVerifier;
|
||||
|
||||
// UI控件
|
||||
private TextView mResultTextView;
|
||||
private TextView mGroupIdTextView;
|
||||
private AlertDialog mTextPwdSelectDialog;
|
||||
private Toast mToast;
|
||||
|
||||
// 是否已经开始业务
|
||||
private boolean mIsWorking = false;
|
||||
// 是否可以鉴别
|
||||
private boolean mCanIdentify = false;
|
||||
// 录音采样率
|
||||
private final int SAMPLE_RATE = 16000;
|
||||
// pcm录音机
|
||||
private PcmRecorder mPcmRecorder;
|
||||
// 进度对话框
|
||||
private ProgressDialog mProDialog;
|
||||
|
||||
|
||||
/**
|
||||
* 声纹鉴别监听器
|
||||
*/
|
||||
private IdentityListener mSearchListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
dismissProDialog();
|
||||
mIsWorking = false;
|
||||
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
if (SpeechEvent.EVENT_VOLUME == eventType) {
|
||||
showTip("音量:" + arg1);
|
||||
} else if (SpeechEvent.EVENT_VAD_EOS == eventType) {
|
||||
showTip("录音结束");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
mCanIdentify = false;
|
||||
dismissProDialog();
|
||||
mIsWorking = false;
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 按压监听器
|
||||
*/
|
||||
private OnTouchListener mPressTouchListener = new OnTouchListener() {
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if( null == mIdVerifier ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
if(!mIsWorking) {
|
||||
vocalSearch();
|
||||
mIsWorking = true;
|
||||
mCanIdentify = true;
|
||||
if(mCanIdentify) {
|
||||
try {
|
||||
mPcmRecorder = new PcmRecorder(SAMPLE_RATE, 40);
|
||||
mPcmRecorder.startRecording(mPcmRecordListener);
|
||||
} catch (SpeechError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
v.performClick();
|
||||
if(mCanIdentify){
|
||||
showProDialog("鉴别中...");
|
||||
}
|
||||
mIdVerifier.stopWrite("ivp");
|
||||
if (null != mPcmRecorder) {
|
||||
mPcmRecorder.stopRecord(true);
|
||||
mIsWorking = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 录音机监听器
|
||||
*/
|
||||
private PcmRecordListener mPcmRecordListener = new PcmRecordListener() {
|
||||
|
||||
@Override
|
||||
public void onRecordStarted(boolean success) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordReleased() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordBuffer(byte[] data, int offset, int length) {
|
||||
StringBuffer params = new StringBuffer();
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
params.append("ptxt=" + mIdentifyNumPwd + ",");
|
||||
params.append("pwdt=" + mPwdType + ",");
|
||||
params.append(",group_id=" + mGroupId +",topc=3");
|
||||
mIdVerifier.writeData("ivp", params.toString(), data, 0, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError e) {
|
||||
dismissProDialog();
|
||||
mCanIdentify = false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_vocal_identify);
|
||||
|
||||
mGroupId = getIntent().getStringExtra("group_id");
|
||||
mIdVerifier = IdentityVerifier.createVerifier(VocalIdentifyActivity.this, new InitListener() {
|
||||
@Override
|
||||
public void onInit(int errorCode) {
|
||||
if (ErrorCode.SUCCESS == errorCode) {
|
||||
showTip("引擎初始化成功");
|
||||
} else {
|
||||
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void handleResult(IdentityResult result) {
|
||||
if (null == result) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String resultStr = result.getResultString();
|
||||
JSONObject resultJson = new JSONObject(resultStr);
|
||||
if(ErrorCode.SUCCESS == resultJson.getInt("ret"))
|
||||
{
|
||||
// 保存到历史记录中
|
||||
/*DemoApp.getmHisList().addHisItem(resultJson.getString("group_id"),
|
||||
resultJson.getString("group_name") + "(" + resultJson.getString("group_id") + ")");
|
||||
FuncUtil.saveObject(VocalIdentifyActivity.this, DemoApp.getmHisList(), DemoApp.HIS_FILE_NAME);*/
|
||||
|
||||
// 跳转到结果展示页面
|
||||
Intent intent = new Intent(VocalIdentifyActivity.this, ResultIdentifyActivity.class);
|
||||
intent.putExtra("result", resultStr);
|
||||
startActivity(intent);
|
||||
this.finish();
|
||||
}
|
||||
else {
|
||||
showTip("鉴别失败!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
TextView title = (TextView) findViewById(R.id.vocal_idf_txt_title);
|
||||
|
||||
mResultTextView = (TextView) findViewById(R.id.vocal_idf_edt_result);
|
||||
mGroupIdTextView = (TextView) findViewById(R.id.vocal_idf_txt_groupid);
|
||||
|
||||
((Button) findViewById(R.id.btn_vocal_idf_press_to_talk)).setOnTouchListener(mPressTouchListener);
|
||||
|
||||
mProDialog = new ProgressDialog(VocalIdentifyActivity.this);
|
||||
mProDialog.setCancelable(true);
|
||||
mProDialog.setTitle("请稍候");
|
||||
// cancel进度框时,取消正在进行的操作
|
||||
mProDialog.setOnCancelListener(new OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mToast = Toast.makeText(VocalIdentifyActivity.this, "", Toast.LENGTH_SHORT);
|
||||
mToast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||
|
||||
mIdentifyNumPwd = VerifierUtil.generateNumberPassword(8);
|
||||
StringBuilder strBufSearch = new StringBuilder();
|
||||
strBufSearch.append("您的鉴别密码:" + mIdentifyNumPwd + "\n");
|
||||
strBufSearch.append("请长按“按住说话”按钮进行鉴别!\n");
|
||||
mResultTextView.setText(strBufSearch.toString());
|
||||
|
||||
mGroupIdTextView.setText(mGroupId);
|
||||
}
|
||||
|
||||
private void vocalSearch() {
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ivp");
|
||||
// 设置会话类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "identify");
|
||||
// 设置组ID
|
||||
mIdVerifier.setParameter("group_id", mGroupId);
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mSearchListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
if (null != mTextPwdSelectDialog) {
|
||||
mTextPwdSelectDialog.dismiss();
|
||||
}
|
||||
|
||||
setResult(RESULT_OK);
|
||||
super.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (null != mPcmRecorder) {
|
||||
mPcmRecorder.stopRecord(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.destroy();
|
||||
mIdVerifier = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
private void dismissProDialog() {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private void showProDialog(String msg) {
|
||||
if (mProDialog != null) {
|
||||
mProDialog.setMessage(msg);
|
||||
mProDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,316 @@
|
||||
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.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.Toast;
|
||||
|
||||
/**
|
||||
* 语音评测demo
|
||||
*/
|
||||
public class IseDemo extends Activity implements OnClickListener {
|
||||
private static String TAG = IseDemo.class.getSimpleName();
|
||||
|
||||
private final static String PREFER_NAME = "ise_settings";
|
||||
private final static int REQUEST_CODE_SETTINGS = 1;
|
||||
|
||||
private EditText mEvaTextEditText;
|
||||
private EditText mResultEditText;
|
||||
private Button mIseStartButton;
|
||||
private Toast mToast;
|
||||
|
||||
// 评测语种
|
||||
private String language;
|
||||
// 评测题型
|
||||
private String category;
|
||||
// 结果等级
|
||||
private String result_level;
|
||||
|
||||
private String mLastResult;
|
||||
private SpeechEvaluator mIse;
|
||||
|
||||
|
||||
// 评测监听接口
|
||||
private EvaluatorListener mEvaluatorListener = new EvaluatorListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(EvaluatorResult result, boolean isLast) {
|
||||
Log.d(TAG, "evaluator result :" + isLast);
|
||||
|
||||
if (isLast) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(result.getResultString());
|
||||
|
||||
if(!TextUtils.isEmpty(builder)) {
|
||||
mResultEditText.setText(builder.toString());
|
||||
}
|
||||
mIseStartButton.setEnabled(true);
|
||||
mLastResult = builder.toString();
|
||||
|
||||
showTip("评测结束");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
mIseStartButton.setEnabled(true);
|
||||
if(error != null) {
|
||||
showTip("error:"+ error.getErrorCode() + "," + error.getErrorDescription());
|
||||
mResultEditText.setText("");
|
||||
mResultEditText.setHint("请点击“开始评测”按钮");
|
||||
} else {
|
||||
Log.d(TAG, "evaluator over");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeginOfSpeech() {
|
||||
// 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入
|
||||
Log.d(TAG, "evaluator begin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndOfSpeech() {
|
||||
// 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入
|
||||
Log.d(TAG, "evaluator stoped");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(int volume, byte[] data) {
|
||||
showTip("当前音量:" + volume);
|
||||
Log.d(TAG, "返回音频数据:"+data.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
|
||||
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
|
||||
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
||||
// Log.d(TAG, "session id =" + sid);
|
||||
// }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.isedemo);
|
||||
|
||||
mIse = SpeechEvaluator.createEvaluator(IseDemo.this, null);
|
||||
initUI();
|
||||
setEvaText();
|
||||
}
|
||||
|
||||
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);
|
||||
mIseStartButton = (Button) findViewById(R.id.ise_start);
|
||||
mIseStartButton.setOnClickListener(IseDemo.this);
|
||||
findViewById(R.id.ise_parse).setOnClickListener(IseDemo.this);
|
||||
findViewById(R.id.ise_stop).setOnClickListener(IseDemo.this);
|
||||
findViewById(R.id.ise_cancel).setOnClickListener(IseDemo.this);
|
||||
|
||||
mToast = Toast.makeText(IseDemo.this, "", Toast.LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( null == mIse ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
case R.id.image_ise_set:
|
||||
Intent intent = new Intent(IseDemo.this, IseSettings.class);
|
||||
startActivityForResult(intent, REQUEST_CODE_SETTINGS);
|
||||
break;
|
||||
case R.id.ise_start:
|
||||
if (mIse == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String evaText = mEvaTextEditText.getText().toString();
|
||||
mLastResult = null;
|
||||
mResultEditText.setText("");
|
||||
mResultEditText.setHint("请朗读以上内容");
|
||||
mIseStartButton.setEnabled(false);
|
||||
|
||||
setParams();
|
||||
int ret = mIse.startEvaluating(evaText, null, mEvaluatorListener);
|
||||
//以下方法为通过直接写入音频的方式进行评测业务
|
||||
/*if (ret != ErrorCode.SUCCESS) {
|
||||
showTip("识别失败,错误码:" + ret);
|
||||
} else {
|
||||
showTip(getString(R.string.text_begin_ise));
|
||||
byte[] audioData = FucUtil.readAudioFile(IseDemo.this,"isetest.wav");
|
||||
if(audioData != null) {
|
||||
//防止写入音频过早导致失败
|
||||
try{
|
||||
new Thread().sleep(100);
|
||||
}catch (InterruptedException e) {
|
||||
Log.d(TAG,"InterruptedException :"+e);
|
||||
}
|
||||
mIse.writeAudio(audioData,0,audioData.length);
|
||||
mIse.stopEvaluating();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
break;
|
||||
case R.id.ise_parse:
|
||||
// 解析最终结果
|
||||
if (!TextUtils.isEmpty(mLastResult)) {
|
||||
XmlResultParser resultParser = new XmlResultParser();
|
||||
Result result = resultParser.parse(mLastResult);
|
||||
|
||||
if (null != result) {
|
||||
mResultEditText.setText(result.toString());
|
||||
} else {
|
||||
showTip("解析结果为空");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case R.id.ise_stop:
|
||||
if (mIse.isEvaluating()) {
|
||||
mResultEditText.setHint("评测已停止,等待结果中...");
|
||||
mIse.stopEvaluating();
|
||||
}
|
||||
break;
|
||||
case R.id.ise_cancel: {
|
||||
mIse.cancel();
|
||||
mIseStartButton.setEnabled(true);
|
||||
mResultEditText.setText("");
|
||||
mResultEditText.setHint("请点击“开始评测”按钮");
|
||||
mLastResult = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (REQUEST_CODE_SETTINGS == requestCode) {
|
||||
setEvaText();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (null != mIse) {
|
||||
mIse.destroy();
|
||||
mIse = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置评测试题
|
||||
private void setEvaText() {
|
||||
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
||||
language = pref.getString(SpeechConstant.LANGUAGE, "zh_cn");
|
||||
category = pref.getString(SpeechConstant.ISE_CATEGORY, "read_sentence");
|
||||
|
||||
String text = "";
|
||||
if ("en_us".equals(language)) {
|
||||
if ("read_word".equals(category)) {
|
||||
text = getString(R.string.text_en_word);
|
||||
} else if ("read_sentence".equals(category)) {
|
||||
text = getString(R.string.text_en_sentence);
|
||||
}
|
||||
} else {
|
||||
// 中文评测
|
||||
if ("read_syllable".equals(category)) {
|
||||
text = getString(R.string.text_cn_syllable);
|
||||
} else if ("read_word".equals(category)) {
|
||||
text = getString(R.string.text_cn_word);
|
||||
} else if ("read_sentence".equals(category)) {
|
||||
text = getString(R.string.text_cn_sentence);
|
||||
}
|
||||
}
|
||||
|
||||
mEvaTextEditText.setText(text);
|
||||
mResultEditText.setText("");
|
||||
mLastResult = null;
|
||||
mResultEditText.setHint("请点击“开始评测”按钮");
|
||||
}
|
||||
|
||||
private void showTip(String str) {
|
||||
if(!TextUtils.isEmpty(str)) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
private void setParams() {
|
||||
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
||||
// 设置评测语言
|
||||
language = pref.getString(SpeechConstant.LANGUAGE, "zh_cn");
|
||||
// 设置需要评测的类型
|
||||
category = pref.getString(SpeechConstant.ISE_CATEGORY, "read_sentence");
|
||||
// 设置结果等级(中文仅支持complete)
|
||||
result_level = pref.getString(SpeechConstant.RESULT_LEVEL, "complete");
|
||||
// 设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理
|
||||
String vad_bos = pref.getString(SpeechConstant.VAD_BOS, "5000");
|
||||
// 设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 自动停止录音
|
||||
String vad_eos = pref.getString(SpeechConstant.VAD_EOS, "1800");
|
||||
// 语音输入超时时间,即用户最多可以连续说多长时间;
|
||||
String speech_timeout = pref.getString(SpeechConstant.KEY_SPEECH_TIMEOUT, "-1");
|
||||
|
||||
mIse.setParameter(SpeechConstant.LANGUAGE, language);
|
||||
mIse.setParameter(SpeechConstant.ISE_CATEGORY, category);
|
||||
mIse.setParameter(SpeechConstant.TEXT_ENCODING, "utf-8");
|
||||
mIse.setParameter(SpeechConstant.VAD_BOS, vad_bos);
|
||||
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");
|
||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
||||
mIse.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
|
||||
mIse.setParameter(SpeechConstant.ISE_AUDIO_PATH, Environment.getExternalStorageDirectory().getAbsolutePath() + "/msc/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();
|
||||
}
|
||||
}
|
@ -0,0 +1,252 @@
|
||||
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;
|
||||
|
||||
public class MainActivity extends Activity implements OnClickListener {
|
||||
|
||||
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);
|
||||
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:
|
||||
// 语音转写
|
||||
intent = new Intent(MainActivity.this, IatDemo.class);
|
||||
break;
|
||||
case 1:
|
||||
// 语法识别
|
||||
intent = new Intent(MainActivity.this, AsrDemo.class);
|
||||
break;
|
||||
case 2:
|
||||
// 语义理解
|
||||
showTip("请登录:http://www.xfyun.cn/ 下载aiui体验吧!");
|
||||
break;
|
||||
case 3:
|
||||
// 语音合成
|
||||
intent = new Intent(MainActivity.this, TtsDemo.class);
|
||||
break;
|
||||
case 4:
|
||||
// 语音评测
|
||||
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);
|
||||
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 void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
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(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
private void mscInit (String serverUrl){
|
||||
// 注意:此接口在非主进程调用会返回null对象,如需在非主进程使用语音功能,请增加参数:SpeechConstant.FORCE_LOGIN+"=true"
|
||||
// 参数间使用半角“,”分隔。
|
||||
// 设置你申请的应用appid,请勿在'='与appid之间添加空格及空转义符
|
||||
|
||||
// 注意: appid 必须和下载的SDK保持一致,否则会出现10407错误
|
||||
StringBuffer bf = new StringBuffer();
|
||||
bf.append("appid="+getString(R.string.app_id));
|
||||
bf.append(",");
|
||||
if (!TextUtils.isEmpty(serverUrl)) {
|
||||
bf.append("server_url="+serverUrl);
|
||||
bf.append(",");
|
||||
}
|
||||
//此处调用与SpeechDemo中重复,两处只调用其一即可
|
||||
SpeechUtility.createUtility(this.getApplicationContext(), bf.toString());
|
||||
// 以下语句用于设置日志开关(默认开启),设置成false时关闭语音云SDK日志打印
|
||||
// Setting.setShowLog(false);
|
||||
}
|
||||
|
||||
private void mscUninit() {
|
||||
if (SpeechUtility.getUtility()!= null) {
|
||||
SpeechUtility.getUtility().destroy();
|
||||
try{
|
||||
new Thread().sleep(40);
|
||||
}catch (InterruptedException e) {
|
||||
Log.w(TAG,"msc uninit failed"+e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (URL_REQUEST_CODE == requestCode) {
|
||||
Log.d(TAG,"onActivityResult>>");
|
||||
try{
|
||||
SharedPreferences pref = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
|
||||
String server_url = pref.getString("url_preference","");
|
||||
String domain = pref.getString("url_edit","");
|
||||
Log.d(TAG,"onActivityResult>>domain = "+domain);
|
||||
if (!TextUtils.isEmpty(domain)) {
|
||||
server_url = "http://"+domain+"/msp.do";
|
||||
}
|
||||
Log.d(TAG,"onActivityResult>>server_url = "+server_url);
|
||||
mscUninit();
|
||||
new Thread().sleep(40);
|
||||
//mscInit(server_url);
|
||||
}catch (Exception e) {
|
||||
showTip("reset url failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.iflytek.voicedemo;
|
||||
|
||||
import android.app.Application;
|
||||
import com.iflytek.cloud.Setting;
|
||||
import com.iflytek.cloud.SpeechUtility;
|
||||
|
||||
public class SpeechApp extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// 应用程序入口处调用,避免手机内存过小,杀死后台进程后通过历史intent进入Activity造成SpeechUtility对象为null
|
||||
// 如在Application中调用初始化,需要在Mainifest中注册该Applicaiton
|
||||
// 注意:此接口在非主进程调用会返回null对象,如需在非主进程使用语音功能,请增加参数:SpeechConstant.FORCE_LOGIN+"=true"
|
||||
// 参数间使用半角“,”分隔。
|
||||
// 设置你申请的应用appid,请勿在'='与appid之间添加空格及空转义符
|
||||
|
||||
// 注意: appid 必须和下载的SDK保持一致,否则会出现10407错误
|
||||
|
||||
SpeechUtility.createUtility(SpeechApp.this, "appid=" + getString(R.string.app_id));
|
||||
|
||||
// 以下语句用于设置日志开关(默认开启),设置成false时关闭语音云SDK日志打印
|
||||
// Setting.setShowLog(false);
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,396 @@
|
||||
package com.iflytek.voicedemo;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.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;
|
||||
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.InitListener;
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
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;
|
||||
|
||||
|
||||
public class TtsDemo extends Activity implements OnClickListener {
|
||||
private static String TAG = TtsDemo.class.getSimpleName();
|
||||
// 语音合成对象
|
||||
private SpeechSynthesizer mTts;
|
||||
|
||||
// 默认发音人
|
||||
private String voicer = "xiaoyan";
|
||||
|
||||
private String[] mCloudVoicersEntries;
|
||||
private String[] mCloudVoicersValue ;
|
||||
String texts = "";
|
||||
|
||||
// 缓冲进度
|
||||
private int mPercentForBuffering = 0;
|
||||
// 播放进度
|
||||
private int mPercentForPlaying = 0;
|
||||
|
||||
// 云端/本地单选按钮
|
||||
private RadioGroup mRadioGroup;
|
||||
// 引擎类型
|
||||
private String mEngineType = SpeechConstant.TYPE_CLOUD;
|
||||
|
||||
private Toast mToast;
|
||||
private SharedPreferences mSharedPreferences;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化Layout。
|
||||
*/
|
||||
private void initLayout() {
|
||||
findViewById(R.id.tts_play).setOnClickListener(TtsDemo.this);
|
||||
findViewById(R.id.tts_cancel).setOnClickListener(TtsDemo.this);
|
||||
findViewById(R.id.tts_pause).setOnClickListener(TtsDemo.this);
|
||||
findViewById(R.id.tts_resume).setOnClickListener(TtsDemo.this);
|
||||
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.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
switch (checkedId) {
|
||||
case R.id.tts_radioCloud:
|
||||
mEngineType = SpeechConstant.TYPE_CLOUD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( null == mTts ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
switch(view.getId()) {
|
||||
case R.id.image_tts_set:
|
||||
if(SpeechConstant.TYPE_CLOUD.equals(mEngineType)){
|
||||
Intent intent = new Intent(TtsDemo.this, TtsSettings.class);
|
||||
startActivity(intent);
|
||||
}else{
|
||||
showTip("请前往xfyun.cn下载离线合成体验");
|
||||
}
|
||||
break;
|
||||
// 开始合成
|
||||
// 收到onCompleted 回调时,合成结束、生成合成音频
|
||||
// 合成的音频格式:只支持pcm格式
|
||||
case R.id.tts_play:
|
||||
// 移动数据分析,收集开始合成事件
|
||||
/*FlowerCollector.onEvent(TtsDemo.this, "tts_play");*/
|
||||
|
||||
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);
|
||||
|
||||
if (code != ErrorCode.SUCCESS) {
|
||||
showTip("语音合成失败,错误码: " + code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
break;
|
||||
// 取消合成
|
||||
case R.id.tts_cancel:
|
||||
mTts.stopSpeaking();
|
||||
break;
|
||||
// 暂停播放
|
||||
case R.id.tts_pause:
|
||||
mTts.pauseSpeaking();
|
||||
break;
|
||||
// 继续播放
|
||||
case R.id.tts_resume:
|
||||
mTts.resumeSpeaking();
|
||||
break;
|
||||
// 选择发音人
|
||||
case R.id.tts_btn_person_select:
|
||||
showPresonSelectDialog();
|
||||
break;
|
||||
}
|
||||
}
|
||||
private int selectedNum = 0;
|
||||
/**
|
||||
* 发音人选择。
|
||||
*/
|
||||
private void showPresonSelectDialog() {
|
||||
switch (mRadioGroup.getCheckedRadioButtonId()) {
|
||||
// 选择在线合成
|
||||
case R.id.tts_radioCloud:
|
||||
new AlertDialog.Builder(this).setTitle("在线合成发音人选项")
|
||||
.setSingleChoiceItems(mCloudVoicersEntries, // 单选框有几项,各是什么名字
|
||||
selectedNum, // 默认的选项
|
||||
new DialogInterface.OnClickListener() { // 点击单选框后的处理
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) { // 点击了哪一项
|
||||
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 {
|
||||
((EditText) findViewById(R.id.tts_text)).setText(R.string.text_tts_source);
|
||||
}
|
||||
selectedNum = which;
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).show();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化监听。
|
||||
*/
|
||||
private InitListener mTtsInitListener = new InitListener() {
|
||||
@Override
|
||||
public void onInit(int code) {
|
||||
Log.d(TAG, "InitListener init() code = " + code);
|
||||
if (code != ErrorCode.SUCCESS) {
|
||||
showTip("初始化失败,错误码:"+code+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
} else {
|
||||
// 初始化成功,之后可以调用startSpeaking方法
|
||||
// 注:有的开发者在onCreate方法中创建完合成对象之后马上就调用startSpeaking进行合成,
|
||||
// 正确的做法是将onCreate中的startSpeaking调用移至这里
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 合成回调监听。
|
||||
*/
|
||||
private SynthesizerListener mTtsListener = new SynthesizerListener() {
|
||||
|
||||
@Override
|
||||
public void onSpeakBegin() {
|
||||
showTip("开始播放");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakPaused() {
|
||||
showTip("暂停播放");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakResumed() {
|
||||
showTip("继续播放");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferProgress(int percent, int beginPos, int endPos,
|
||||
String info) {
|
||||
// 合成进度
|
||||
Log.e("MscSpeechLog_", "percent =" + percent);
|
||||
mPercentForBuffering = percent;
|
||||
showTip(String.format(getString(R.string.tts_toast_format),
|
||||
mPercentForBuffering, mPercentForPlaying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakProgress(int percent, int beginPos, int endPos) {
|
||||
// 播放进度
|
||||
Log.e("MscSpeechLog_", "percent =" + percent);
|
||||
mPercentForPlaying = percent;
|
||||
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);
|
||||
((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(error.getPlainDescription(true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
|
||||
// 若使用本地能力,会话id为null
|
||||
if (SpeechEvent.EVENT_SESSION_ID == eventType) {
|
||||
String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
|
||||
Log.d(TAG, "session id =" + sid);
|
||||
}
|
||||
|
||||
//当设置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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private void showTip(final String str) {
|
||||
Toast.makeText(this,str,Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数设置
|
||||
* @return
|
||||
*/
|
||||
private void setParam(){
|
||||
// 清空参数
|
||||
mTts.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 根据合成引擎设置相应参数
|
||||
if(mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
|
||||
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
|
||||
//支持实时音频返回,仅在synthesizeToUri条件下支持
|
||||
mTts.setParameter(SpeechConstant.TTS_DATA_NOTIFY, "1");
|
||||
// mTts.setParameter(SpeechConstant.TTS_BUFFER_TIME,"1");
|
||||
|
||||
// 设置在线合成发音人
|
||||
mTts.setParameter(SpeechConstant.VOICE_NAME, voicer);
|
||||
//设置合成语速
|
||||
mTts.setParameter(SpeechConstant.SPEED, mSharedPreferences.getString("speed_preference", "50"));
|
||||
//设置合成音调
|
||||
mTts.setParameter(SpeechConstant.PITCH, mSharedPreferences.getString("pitch_preference", "50"));
|
||||
//设置合成音量
|
||||
mTts.setParameter(SpeechConstant.VOLUME, mSharedPreferences.getString("volume_preference", "50"));
|
||||
}else {
|
||||
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
|
||||
mTts.setParameter(SpeechConstant.VOICE_NAME, "");
|
||||
|
||||
}
|
||||
|
||||
//设置播放器音频流类型
|
||||
mTts.setParameter(SpeechConstant.STREAM_TYPE, mSharedPreferences.getString("stream_preference", "3"));
|
||||
// 设置播放合成音频打断音乐播放,默认为true
|
||||
mTts.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "false");
|
||||
|
||||
// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
|
||||
mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "pcm");
|
||||
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/tts.pcm");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if( null != mTts ){
|
||||
mTts.stopSpeaking();
|
||||
// 退出时释放连接
|
||||
mTts.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
try {
|
||||
if(memFile == null)
|
||||
{
|
||||
Log.e("MscSpeechLog_","ffffffffff");
|
||||
String mFilepath = Environment.getExternalStorageDirectory()+"/1.pcm";
|
||||
memFile = new MemoryFile(mFilepath,1920000);
|
||||
memFile.allowPurging(false);
|
||||
}
|
||||
memFile.writeBytes(data, 0, (int)mTotalSize, data.length);
|
||||
mTotalSize += data.length;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,512 @@
|
||||
package com.iflytek.voicedemo.faceonline;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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;
|
||||
import com.iflytek.cloud.IdentityListener;
|
||||
import com.iflytek.cloud.IdentityResult;
|
||||
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;
|
||||
|
||||
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;
|
||||
// authid为6-18个字符长度,用于唯一标识用户
|
||||
private String mAuthid = null;
|
||||
private Toast mToast;
|
||||
// 进度对话框
|
||||
private ProgressDialog mProDialog;
|
||||
private EditText online_authid;
|
||||
// 拍照得到的照片文件
|
||||
private File mPictureFile;
|
||||
// FaceRequest对象,集成了人脸识别的各种功能
|
||||
//private FaceRequest mFaceRequest;
|
||||
|
||||
//采用身份识别接口进行在线人脸识别
|
||||
private IdentityVerifier mIdVerifier;
|
||||
|
||||
// 模型操作
|
||||
private int mModelCmd;
|
||||
// 删除模型
|
||||
private final static int MODEL_DEL = 1;
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.online_facedemo);
|
||||
findViewById(R.id.online_pick).setOnClickListener(OnlineFaceDemo.this);
|
||||
findViewById(R.id.online_reg).setOnClickListener(OnlineFaceDemo.this);
|
||||
findViewById(R.id.online_verify).setOnClickListener(OnlineFaceDemo.this);
|
||||
findViewById(R.id.online_camera).setOnClickListener(OnlineFaceDemo.this);
|
||||
findViewById(R.id.btn_modle_delete).setOnClickListener(OnlineFaceDemo.this);
|
||||
findViewById(R.id.btn_identity).setOnClickListener(OnlineFaceDemo.this);
|
||||
online_authid = (EditText) findViewById(R.id.online_authid);
|
||||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
|
||||
|
||||
mProDialog = new ProgressDialog(this);
|
||||
mProDialog.setCancelable(true);
|
||||
mProDialog.setTitle("请稍后");
|
||||
|
||||
mProDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
// cancel进度框时,取消正在进行的操作
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mIdVerifier = IdentityVerifier.createVerifier(OnlineFaceDemo.this, new InitListener() {
|
||||
@Override
|
||||
public void onInit(int errorCode) {
|
||||
if (ErrorCode.SUCCESS == errorCode) {
|
||||
showTip("引擎初始化成功");
|
||||
} else {
|
||||
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void register(JSONObject obj) throws JSONException {
|
||||
int ret = obj.getInt("ret");
|
||||
if (ret != 0) {
|
||||
showTip("注册失败");
|
||||
return;
|
||||
}
|
||||
if ("success".equals(obj.get("rst"))) {
|
||||
showTip("注册成功");
|
||||
} else {
|
||||
showTip("注册失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void verify(JSONObject obj) throws JSONException {
|
||||
int ret = obj.getInt("ret");
|
||||
if (ret != 0) {
|
||||
showTip("验证失败");
|
||||
return;
|
||||
}
|
||||
if ("success".equals(obj.get("rst"))) {
|
||||
if (obj.getBoolean("verf")) {
|
||||
showTip("通过验证,欢迎回来!");
|
||||
} else {
|
||||
showTip("验证不通过");
|
||||
}
|
||||
} else {
|
||||
showTip("验证失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 人脸注册监听器
|
||||
*/
|
||||
private IdentityListener mEnrollListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject object = new JSONObject(result.getResultString());
|
||||
int ret = object.getInt("ret");
|
||||
|
||||
if (ErrorCode.SUCCESS == ret) {
|
||||
showTip("注册成功");
|
||||
}else {
|
||||
showTip(new SpeechError(ret).getPlainDescription(true));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 人脸验证监听器
|
||||
*/
|
||||
private IdentityListener mVerifyListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject object = new JSONObject(result.getResultString());
|
||||
Log.d(TAG,"object is: "+object.toString());
|
||||
String decision = object.getString("decision");
|
||||
|
||||
if ("accepted".equalsIgnoreCase(decision)) {
|
||||
showTip("通过验证");
|
||||
} else {
|
||||
showTip("验证失败");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 人脸模型操作监听器
|
||||
*/
|
||||
private IdentityListener mModelListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
JSONObject jsonResult = null;
|
||||
int ret = ErrorCode.SUCCESS;
|
||||
try {
|
||||
jsonResult = new JSONObject(result.getResultString());
|
||||
ret = jsonResult.getInt("ret");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 根据操作类型判断结果类型
|
||||
switch (mModelCmd) {
|
||||
case MODEL_DEL:
|
||||
if (ErrorCode.SUCCESS == ret) {
|
||||
online_authid.setEnabled(true);
|
||||
showTip("删除成功");
|
||||
} else {
|
||||
showTip("删除失败");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
// 弹出错误信息
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
private void executeModelCommand(String cmd) {
|
||||
// 设置模型参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ifr", cmd, params.toString(), mModelListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int ret = ErrorCode.SUCCESS;
|
||||
mAuthid = online_authid.getText().toString();
|
||||
if(TextUtils.isEmpty(mAuthid)) {
|
||||
showTip("请输入用户ID");
|
||||
return;
|
||||
}else {
|
||||
online_authid.setEnabled(false);
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
case R.id.online_pick:
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_PICK);
|
||||
startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
|
||||
break;
|
||||
case R.id.online_reg:
|
||||
if (TextUtils.isEmpty(mAuthid)) {
|
||||
showTip("authid不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (null != mImageData) {
|
||||
mProDialog.setMessage("注册中...");
|
||||
mProDialog.show();
|
||||
// 设置用户标识,格式为6-18个字符(由字母、数字、下划线组成,不得以数字开头,不能包含空格)。
|
||||
// 当不设置时,云端将使用用户设备的设备ID来标识终端用户。
|
||||
// 设置人脸注册参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ifr");
|
||||
// 设置会话类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "enroll");
|
||||
// 设置用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, mAuthid);
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mEnrollListener);
|
||||
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
// 向子业务写入数据,人脸数据可以一次写入
|
||||
mIdVerifier.writeData("ifr", params.toString(), mImageData, 0, mImageData.length);
|
||||
// 停止写入
|
||||
mIdVerifier.stopWrite("ifr");
|
||||
} else {
|
||||
showTip("请选择图片后再注册");
|
||||
}
|
||||
break;
|
||||
case R.id.online_verify:
|
||||
mAuthid = ((EditText) findViewById(R.id.online_authid)).getText().toString();
|
||||
if (TextUtils.isEmpty(mAuthid)) {
|
||||
showTip("authid不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (null != mImageData) {
|
||||
mProDialog.setMessage("验证中...");
|
||||
mProDialog.show();
|
||||
// 设置人脸验证参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ifr");
|
||||
// 设置会话类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "verify");
|
||||
// 设置验证模式,单一验证模式:sin
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_VCM, "sin");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, mAuthid);
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mVerifyListener);
|
||||
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
// 向子业务写入数据,人脸数据可以一次写入
|
||||
mIdVerifier.writeData("ifr", params.toString(), mImageData, 0, mImageData.length);
|
||||
// 停止写入
|
||||
mIdVerifier.stopWrite("ifr");
|
||||
} else {
|
||||
showTip("请选择图片后再验证");
|
||||
}
|
||||
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);
|
||||
break;
|
||||
case R.id.btn_modle_delete:
|
||||
// 人脸模型删除
|
||||
mModelCmd = MODEL_DEL;
|
||||
executeModelCommand("delete");
|
||||
break;
|
||||
case R.id.btn_identity:
|
||||
Intent init = new Intent(OnlineFaceDemo.this, GroupManagerActivity.class);
|
||||
init.putExtra("auth_id",mAuthid);
|
||||
init.putExtra("mfv_scenes","ifr");
|
||||
startActivity(init);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}//end of switch
|
||||
|
||||
if( ErrorCode.SUCCESS != ret ){
|
||||
mProDialog.dismiss();
|
||||
showTip( "出现错误:"+ret );
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
// 跳转到图片裁剪页面
|
||||
FaceUtil.cropPicture(this,Uri.fromFile(new File(fileSrc)));
|
||||
} else if (requestCode == REQUEST_CAMERA_IMAGE) {
|
||||
if (null == mPictureFile) {
|
||||
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);
|
||||
}
|
||||
// 获取图片保存路径
|
||||
fileSrc = FaceUtil.getImagePath(OnlineFaceDemo.this);
|
||||
// 获取图片的宽和高
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
mImage = BitmapFactory.decodeFile(fileSrc, options);
|
||||
|
||||
// 压缩图片
|
||||
options.inSampleSize = Math.max(1, (int) Math.ceil(Math.max(
|
||||
(double) options.outWidth / 1024f,
|
||||
(double) options.outHeight / 1024f)));
|
||||
options.inJustDecodeBounds = false;
|
||||
mImage = BitmapFactory.decodeFile(fileSrc, options);
|
||||
|
||||
|
||||
// 若mImageBitmap为空则图片信息不能正常获取
|
||||
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
|
||||
public void finish() {
|
||||
if (null != mProDialog) {
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
super.finish();
|
||||
}
|
||||
|
||||
private void updateGallery(String filename) {
|
||||
MediaScannerConnection.scanFile(this, new String[] {filename}, null,
|
||||
new MediaScannerConnection.OnScanCompletedListener() {
|
||||
|
||||
@Override
|
||||
public void onScanCompleted(String path, Uri uri) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,696 @@
|
||||
package com.iflytek.voicedemo.vocalverify;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
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.IdentityListener;
|
||||
import com.iflytek.cloud.IdentityResult;
|
||||
import com.iflytek.cloud.IdentityVerifier;
|
||||
import com.iflytek.cloud.InitListener;
|
||||
import com.iflytek.cloud.SpeechConstant;
|
||||
import com.iflytek.cloud.SpeechError;
|
||||
import com.iflytek.cloud.SpeechEvent;
|
||||
import com.iflytek.cloud.record.PcmRecorder;
|
||||
import com.iflytek.cloud.util.VerifierUtil;
|
||||
import com.iflytek.voicedemo.IdentifyGroup.GroupManagerActivity;
|
||||
import com.iflytek.voicedemo.R;
|
||||
|
||||
/**
|
||||
* 声纹密码示例
|
||||
*
|
||||
* @author hjyu
|
||||
* @date 2017/9/28.
|
||||
* @see <a href="http://www.xfyun.cn">讯飞开放平台</a>
|
||||
*/
|
||||
public class VocalVerifyDemo extends Activity implements OnClickListener,View.OnTouchListener {
|
||||
private static final String TAG = VocalVerifyDemo.class.getSimpleName();
|
||||
// 密码类型
|
||||
// 默认为数字密码
|
||||
private int mPwdType = 3;
|
||||
// 数字密码类型为3,其他类型暂未开放
|
||||
private static final int PWD_TYPE_NUM = 3;
|
||||
|
||||
// 会话类型
|
||||
private int mSST = 0;
|
||||
// 注册
|
||||
private static final int SST_ENROLL = 0;
|
||||
// 验证
|
||||
private static final int SST_VERIFY = 1;
|
||||
|
||||
// 模型操作类型
|
||||
private int mModelCmd;
|
||||
// 查询模型
|
||||
private static final int MODEL_QUE = 0;
|
||||
// 删除模型
|
||||
private static final int MODEL_DEL = 1;
|
||||
|
||||
// 用户id,唯一标识
|
||||
private String authid;
|
||||
// 身份验证对象
|
||||
private IdentityVerifier mIdVerifier;
|
||||
// 数字声纹密码
|
||||
private String mNumPwd = "";
|
||||
// 数字声纹密码段,默认有5段
|
||||
private String[] mNumPwdSegs;
|
||||
// 用于验证的数字密码
|
||||
private String mVerifyNumPwd = "";
|
||||
|
||||
private EditText mResultEditText;
|
||||
private Button btn_start_record;
|
||||
private EditText mAuthidEditText;
|
||||
private RadioGroup mSstTypeGroup;
|
||||
private Toast mToast;
|
||||
|
||||
// 是否可以录音
|
||||
private boolean mCanStartRecord = false;
|
||||
// 是否可以录音
|
||||
private boolean isStartWork = false;
|
||||
// 录音采样率
|
||||
private final int SAMPLE_RATE = 16000;
|
||||
// pcm录音机
|
||||
private PcmRecorder mPcmRecorder;
|
||||
// 进度对话框
|
||||
private ProgressDialog mProDialog;
|
||||
|
||||
/**
|
||||
* 下载密码监听器
|
||||
*/
|
||||
private IdentityListener mDownloadPwdListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
mAuthidEditText.setEnabled(false);//密码获取成功后,authid不可再变动
|
||||
|
||||
mProDialog.dismiss();
|
||||
btn_start_record.setClickable(true);
|
||||
switch (mPwdType) {
|
||||
case PWD_TYPE_NUM:
|
||||
StringBuffer numberString = new StringBuffer();
|
||||
try {
|
||||
JSONObject object = new JSONObject(result.getResultString());
|
||||
if (!object.has("num_pwd")) {
|
||||
mNumPwd = null;
|
||||
return;
|
||||
}
|
||||
|
||||
JSONArray pwdArray = object.optJSONArray("num_pwd");
|
||||
numberString.append(pwdArray.get(0));
|
||||
for (int i = 1; i < pwdArray.length(); i++) {
|
||||
numberString.append("-" + pwdArray.get(i));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mNumPwd = numberString.toString();
|
||||
mNumPwdSegs = mNumPwd.split("-");
|
||||
|
||||
mResultEditText.setText("您的注册密码:\n" + mNumPwd + "\n请长按“按住说话”按钮进行注册\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
mProDialog.dismiss();
|
||||
mAuthidEditText.setEnabled(true);
|
||||
// 下载密码时,恢复按住说话触摸
|
||||
// 下载密码时,恢复按住说话触摸
|
||||
btn_start_record.setClickable(true);
|
||||
mResultEditText.setText("密码下载失败!" + error.getPlainDescription(true));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 声纹注册监听器
|
||||
*/
|
||||
private IdentityListener mEnrollListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, result.getResultString());
|
||||
|
||||
JSONObject jsonResult = null;
|
||||
try {
|
||||
jsonResult = new JSONObject(result.getResultString());
|
||||
int ret = jsonResult.getInt("ret");
|
||||
|
||||
if (ErrorCode.SUCCESS == ret) {
|
||||
|
||||
final int suc = Integer.parseInt(jsonResult.optString("suc"));
|
||||
final int rgn = Integer.parseInt(jsonResult.optString("rgn"));
|
||||
|
||||
if (suc == rgn) {
|
||||
mResultEditText.setText("注册成功");
|
||||
|
||||
mCanStartRecord = false;
|
||||
isStartWork = false;
|
||||
if (mPcmRecorder != null) {
|
||||
mPcmRecorder.stopRecord(true);
|
||||
}
|
||||
} else {
|
||||
int nowTimes = suc + 1;
|
||||
int leftTimes = 5 - nowTimes;
|
||||
|
||||
StringBuffer strBuffer = new StringBuffer();
|
||||
strBuffer.append("请长按“按住说话”按钮!\n");
|
||||
strBuffer.append("请读出:" + mNumPwdSegs[nowTimes - 1] + "\n");
|
||||
strBuffer.append("训练 第" + nowTimes + "遍,剩余" + leftTimes + "遍");
|
||||
mResultEditText.setText(strBuffer.toString());
|
||||
}
|
||||
|
||||
} else {
|
||||
showTip(new SpeechError(ret).getPlainDescription(true));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle bundle) {
|
||||
if (SpeechEvent.EVENT_VOLUME == eventType) {
|
||||
showTip("音量:" + arg1);
|
||||
} else if (SpeechEvent.EVENT_VAD_EOS == eventType) {
|
||||
showTip("录音结束");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
isStartWork = false;
|
||||
|
||||
StringBuffer errorResult = new StringBuffer();
|
||||
errorResult.append("注册失败!\n");
|
||||
errorResult.append("错误信息:" + error.getPlainDescription(true) + "\n");
|
||||
errorResult.append("请长按“按住说话”重新注册!");
|
||||
mResultEditText.setText(errorResult.toString());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 声纹验证监听器
|
||||
*/
|
||||
private IdentityListener mVerifyListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, "verify:" + result.getResultString());
|
||||
|
||||
try {
|
||||
JSONObject object = new JSONObject(result.getResultString());
|
||||
String decision = object.getString("decision");
|
||||
|
||||
if ("accepted".equalsIgnoreCase(decision)) {
|
||||
mResultEditText.setText("验证通过");
|
||||
} else {
|
||||
mResultEditText.setText("验证失败");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
isStartWork = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
if (SpeechEvent.EVENT_VOLUME == eventType) {
|
||||
showTip("音量:" + arg1);
|
||||
} else if (SpeechEvent.EVENT_VAD_EOS == eventType) {
|
||||
showTip("录音结束");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
isStartWork = false;
|
||||
mCanStartRecord = false;
|
||||
|
||||
StringBuffer errorResult = new StringBuffer();
|
||||
errorResult.append("验证失败!\n");
|
||||
errorResult.append("错误信息:" + error.getPlainDescription(true) + "\n");
|
||||
errorResult.append("请长按“按住说话”重新验证!");
|
||||
mResultEditText.setText(errorResult.toString());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 声纹模型操作监听器
|
||||
*/
|
||||
private IdentityListener mModelListener = new IdentityListener() {
|
||||
|
||||
@Override
|
||||
public void onResult(IdentityResult result, boolean islast) {
|
||||
Log.d(TAG, "model operation:" + result.getResultString());
|
||||
|
||||
mProDialog.dismiss();
|
||||
|
||||
JSONObject jsonResult = null;
|
||||
int ret = ErrorCode.SUCCESS;
|
||||
try {
|
||||
jsonResult = new JSONObject(result.getResultString());
|
||||
ret = jsonResult.getInt("ret");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
switch (mModelCmd) {
|
||||
case MODEL_QUE:
|
||||
if (ErrorCode.SUCCESS == ret) {
|
||||
showTip("模型存在");
|
||||
} else {
|
||||
showTip("模型不存在");
|
||||
}
|
||||
break;
|
||||
case MODEL_DEL:
|
||||
if (ErrorCode.SUCCESS == ret) {
|
||||
mAuthidEditText.setEnabled(true);//模型删除后,可重新配置authid
|
||||
showTip("模型已删除");
|
||||
} else {
|
||||
showTip("模型删除失败");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError error) {
|
||||
mProDialog.dismiss();
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 录音机监听器
|
||||
*/
|
||||
private PcmRecorder.PcmRecordListener mPcmRecordListener = new PcmRecorder.PcmRecordListener() {
|
||||
|
||||
@Override
|
||||
public void onRecordStarted(boolean success) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordReleased() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordBuffer(byte[] data, int offset, int length) {
|
||||
StringBuffer params = new StringBuffer();
|
||||
|
||||
switch (mSST) {
|
||||
case SST_ENROLL:
|
||||
params.append("rgn=5,");
|
||||
params.append("ptxt=" + mNumPwd + ",");
|
||||
params.append("pwdt=" + mPwdType + ",");
|
||||
mIdVerifier.writeData("ivp", params.toString(), data, 0, length);
|
||||
break;
|
||||
case SST_VERIFY:
|
||||
params.append("ptxt=" + mVerifyNumPwd + ",");
|
||||
params.append("pwdt=" + mPwdType + ",");
|
||||
mIdVerifier.writeData("ivp", params.toString(), data, 0, length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SpeechError e) {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.isvdemo);
|
||||
|
||||
initUi();
|
||||
|
||||
mIdVerifier = IdentityVerifier.createVerifier(VocalVerifyDemo.this, new InitListener() {
|
||||
|
||||
@Override
|
||||
public void onInit(int errorCode) {
|
||||
if (ErrorCode.SUCCESS == errorCode) {
|
||||
showTip("引擎初始化成功");
|
||||
} else {
|
||||
showTip("引擎初始化失败,错误码:" + errorCode+",请点击网址https://www.xfyun.cn/document/error-code查询解决方案");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
private void initUi() {
|
||||
mResultEditText = (EditText) findViewById(R.id.edt_result);
|
||||
mAuthidEditText = (EditText) findViewById(R.id.set_authId);
|
||||
btn_start_record = (Button) findViewById(R.id.isv_reocrd);
|
||||
btn_start_record.setOnTouchListener(VocalVerifyDemo.this);
|
||||
findViewById(R.id.isv_getpassword).setOnClickListener(VocalVerifyDemo.this);
|
||||
findViewById(R.id.isv_search).setOnClickListener(VocalVerifyDemo.this);
|
||||
findViewById(R.id.isv_delete).setOnClickListener(VocalVerifyDemo.this);
|
||||
findViewById(R.id.isv_identity).setOnClickListener(VocalVerifyDemo.this);
|
||||
|
||||
|
||||
mToast = Toast.makeText(VocalVerifyDemo.this, "", Toast.LENGTH_SHORT);
|
||||
mToast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||
|
||||
mProDialog = new ProgressDialog(VocalVerifyDemo.this);
|
||||
mProDialog.setCancelable(true);
|
||||
mProDialog.setTitle("请稍候");
|
||||
// cancel进度框时,取消正在进行的操作
|
||||
mProDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 密码选择RadioGroup初始化
|
||||
mSstTypeGroup = (RadioGroup) findViewById(R.id.vocal_radioGroup1);
|
||||
mSstTypeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
if( null == mIdVerifier ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
|
||||
return;
|
||||
}
|
||||
|
||||
// 取消之前操作
|
||||
if (mIdVerifier.isWorking()) {
|
||||
mIdVerifier.cancel();
|
||||
}
|
||||
cancelOperation();
|
||||
|
||||
switch (checkedId) {
|
||||
case R.id.vocal_radioVerify:
|
||||
// 设置会话类型为验证
|
||||
mSST = SST_VERIFY;
|
||||
mVerifyNumPwd = VerifierUtil.generateNumberPassword(8);
|
||||
|
||||
StringBuffer strBuffer = new StringBuffer();
|
||||
strBuffer.append("您的验证密码:" + mVerifyNumPwd + "\n");
|
||||
strBuffer.append("请长按“按住说话”按钮进行验证!\n");
|
||||
mResultEditText.setText(strBuffer.toString());
|
||||
break;
|
||||
case R.id.vocal_radioEnroll:
|
||||
// 设置会话类型为验证
|
||||
mSST = SST_ENROLL;
|
||||
|
||||
if (null == mNumPwdSegs) {
|
||||
// 首次注册密码为空时,调用下载密码
|
||||
downloadPwd();
|
||||
} else {
|
||||
mResultEditText.setText("请长按“按住说话”按钮进行注册\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void cancelOperation() {
|
||||
isStartWork = false;
|
||||
mIdVerifier.cancel();
|
||||
|
||||
if (null != mPcmRecorder) {
|
||||
mPcmRecorder.stopRecord(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if( !checkInstance() ){
|
||||
return false;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
authid = getAuthid();
|
||||
if(TextUtils.isEmpty(authid)) {
|
||||
showTip("请输入authid");
|
||||
break;
|
||||
}
|
||||
if (!isStartWork) {
|
||||
// 根据业务类型调用服务
|
||||
if (mSST == SST_ENROLL) {
|
||||
if (null == mNumPwdSegs) {
|
||||
// 启动录音机时密码为空,中断此次操作,下载密码
|
||||
downloadPwd();
|
||||
break;
|
||||
}
|
||||
vocalEnroll();
|
||||
} else if (mSST == SST_VERIFY) {
|
||||
vocalVerify();
|
||||
} else {
|
||||
showTip("请先选择相应业务!");
|
||||
break;
|
||||
}
|
||||
isStartWork = true;
|
||||
mCanStartRecord = true;
|
||||
}
|
||||
if (mCanStartRecord) {
|
||||
try {
|
||||
mPcmRecorder = new PcmRecorder(SAMPLE_RATE, 40);
|
||||
mPcmRecorder.startRecording(mPcmRecordListener);
|
||||
} catch (SpeechError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
v.performClick();
|
||||
|
||||
mIdVerifier.stopWrite("ivp");
|
||||
if (null != mPcmRecorder) {
|
||||
|
||||
mPcmRecorder.stopRecord(true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( !checkInstance() ){
|
||||
return;
|
||||
}
|
||||
authid = getAuthid();
|
||||
if(TextUtils.isEmpty(authid)){
|
||||
showTip("用户id为空,请重新输入");
|
||||
return;
|
||||
}
|
||||
|
||||
// 取消先前操作
|
||||
cancelOperation();
|
||||
switch (v.getId()) {
|
||||
case R.id.isv_getpassword:
|
||||
if (null == mNumPwdSegs) {
|
||||
// 首次注册密码为空时,调用下载密码
|
||||
downloadPwd();
|
||||
} else {
|
||||
showTip("数字密码已存在");
|
||||
}
|
||||
break;
|
||||
case R.id.isv_search:
|
||||
// 执行查询模型
|
||||
mModelCmd = MODEL_QUE;
|
||||
executeModelCommand("query");
|
||||
break;
|
||||
case R.id.isv_delete:
|
||||
// 执行删除模型
|
||||
mModelCmd = MODEL_DEL;
|
||||
executeModelCommand("delete");
|
||||
break;
|
||||
case R.id.isv_identity:
|
||||
Intent init = new Intent(VocalVerifyDemo.this, GroupManagerActivity.class);
|
||||
init.putExtra("auth_id",authid);
|
||||
init.putExtra("mfv_scenes","ivp");
|
||||
startActivity(init);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
private void vocalEnroll() {
|
||||
StringBuffer strBuffer = new StringBuffer();
|
||||
strBuffer.append("请长按“按住说话”按钮!\n");
|
||||
strBuffer.append("请读出:" + mNumPwdSegs[0] + "\n");
|
||||
strBuffer.append("训练 第" + 1 + "遍,剩余4遍\n");
|
||||
mResultEditText.setText(strBuffer.toString());
|
||||
|
||||
// 设置声纹注册参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ivp");
|
||||
// 设置会话类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "enroll");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authid);
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mEnrollListener);
|
||||
}
|
||||
|
||||
private void vocalVerify() {
|
||||
|
||||
StringBuffer strBuffer = new StringBuffer();
|
||||
strBuffer.append("您的验证密码:" + mVerifyNumPwd + "\n");
|
||||
strBuffer.append("请长按“按住说话”按钮进行验证!\n");
|
||||
mResultEditText.setText(strBuffer.toString());
|
||||
// 设置声纹验证参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ivp");
|
||||
// 设置会话类型
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SST, "verify");
|
||||
// 验证模式,单一验证模式:sin
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_VCM, "sin");
|
||||
// 用户的唯一标识,在声纹业务获取注册、验证、查询和删除模型时都要填写,不能为空
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authid);
|
||||
// 设置监听器,开始会话
|
||||
mIdVerifier.startWorking(mVerifyListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载密码
|
||||
*/
|
||||
private void downloadPwd() {
|
||||
authid = getAuthid();
|
||||
if(TextUtils.isEmpty(authid)) {
|
||||
showTip("请输入authid");
|
||||
return;
|
||||
}
|
||||
// 获取密码之前先终止之前的操作
|
||||
mIdVerifier.cancel();
|
||||
mNumPwd = null;
|
||||
// 下载密码时,按住说话触摸无效
|
||||
btn_start_record.setClickable(false);
|
||||
|
||||
mProDialog.setMessage("下载中...");
|
||||
mProDialog.show();
|
||||
|
||||
// 设置下载密码参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ivp");
|
||||
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
StringBuffer params = new StringBuffer();
|
||||
// 设置模型操作的密码类型
|
||||
params.append("pwdt=" + mPwdType + ",");
|
||||
// 执行密码下载操作
|
||||
int ret = mIdVerifier.execute("ivp", "download", params.toString(), mDownloadPwdListener);
|
||||
if (ret!= 0)
|
||||
mProDialog.dismiss();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 模型操作
|
||||
* @param cmd 命令
|
||||
*/
|
||||
private void executeModelCommand(String cmd) {
|
||||
if ("query".equals(cmd)) {
|
||||
mProDialog.setMessage("查询中...");
|
||||
} else if ("delete".equals(cmd)) {
|
||||
mProDialog.setMessage("删除中...");
|
||||
}
|
||||
mProDialog.show();
|
||||
// 设置声纹模型参数
|
||||
// 清空参数
|
||||
mIdVerifier.setParameter(SpeechConstant.PARAMS, null);
|
||||
// 设置会话场景
|
||||
mIdVerifier.setParameter(SpeechConstant.MFV_SCENES, "ivp");
|
||||
// 用户id
|
||||
mIdVerifier.setParameter(SpeechConstant.AUTH_ID, authid);
|
||||
|
||||
// 子业务执行参数,若无可以传空字符传
|
||||
StringBuffer params3 = new StringBuffer();
|
||||
// 设置模型操作的密码类型
|
||||
params3.append("pwdt=" + mPwdType + ",");
|
||||
// 执行模型操作
|
||||
mIdVerifier.execute("ivp", cmd, params3.toString(), mModelListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (null != mIdVerifier) {
|
||||
mIdVerifier.destroy();
|
||||
mIdVerifier = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void showTip(final String str) {
|
||||
mToast.setText(str);
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
private boolean checkInstance(){
|
||||
if( null == mIdVerifier ){
|
||||
// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
|
||||
this.showTip( "创建对象失败,请确认 libmsc.so 放置正确,\n 且有调用 createUtility 进行初始化" );
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private String getAuthid(){
|
||||
String id = mAuthidEditText.getText()==null?null:mAuthidEditText.getText().toString();
|
||||
return id;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@color/list_backgroud_color"></item>
|
||||
<item android:drawable="@drawable/layout_backgroud"></item>
|
||||
</selector>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@drawable/setting" android:state_focused="true" android:state_pressed="false"/>
|
||||
<item android:drawable="@drawable/setting_p" android:state_focused="true" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/setting_p" android:state_focused="false" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/setting"></item>
|
||||
|
||||
</selector>
|
BIN
src/android/sample/speechDemo/src/main/res/drawable/setting.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 2.1 KiB |
BIN
src/android/sample/speechDemo/src/main/res/drawable/user.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/title_face_idf"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/online_img"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/no_photo" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/txt_groupid"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:padding="5dp"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_pick"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="选图"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_camera"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="拍照"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_identity"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1:N验证"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,15 @@
|
||||
<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" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lv_my_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:cacheColorHint="#00000000"
|
||||
android:fadingEdge="none"
|
||||
android:listSelector="#00000000"
|
||||
android:scrollbars="none" />
|
||||
</RelativeLayout>
|
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/rllyt_idf_result_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_idf_result_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_height="30dp"
|
||||
android:gravity="center"
|
||||
android:textSize="26sp"
|
||||
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" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lly_group_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="组名称:"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_group_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_below="@id/lly_group_name"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:text="相似度排名:"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lv_identify_result"
|
||||
android:layout_below="@id/txt_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_alignLeft="@id/txt_hint"
|
||||
android:fadingEdge="none"
|
||||
android:cacheColorHint="#00000000"
|
||||
android:listSelector="#00000000" >
|
||||
</ListView>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/vocal_idf_rllyt_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vocal_idf_txt_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_height="35dp"
|
||||
android:gravity="center"
|
||||
android:textSize="26sp"
|
||||
android:text="@string/title_vocal_idf"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="250dp"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vocal_idf_edt_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="top|left"
|
||||
android:minLines="4"
|
||||
android:background="@null"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textSize="20sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="27dp"
|
||||
android:layout_marginRight="27dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vocal_idf_txt_tag_groupid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="组ID:"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vocal_idf_txt_groupid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_vocal_idf_press_to_talk"
|
||||
android:layout_width="107dp"
|
||||
android:layout_height="95dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:text="按住说话"/>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,213 @@
|
||||
<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">
|
||||
|
||||
<!-- 标题栏 -->
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rllyt_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_login_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="center"
|
||||
android:text="组管理"
|
||||
android:textSize="24sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/user_info_layout"
|
||||
android:layout_below="@id/rllyt_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center" >
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="18dp"
|
||||
android:src="@drawable/user" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_gravity="center"
|
||||
android:maxLength="11"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/group_create_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/user_info_layout"
|
||||
android:layout_marginTop="25dp"
|
||||
android:paddingBottom="10dp" >
|
||||
|
||||
<View
|
||||
android:id="@+id/line_create"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#e5e5e6" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llyt_groupname_input_panel"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/line_create"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_group_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="35dp"
|
||||
android:background="#00000000"
|
||||
android:ems="20"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="请输入组名用于创建组..."
|
||||
android:inputType="text"
|
||||
android:paddingLeft="5dp"
|
||||
android:textSize="18sp" >
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_group_create"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_below="@id/line_create"
|
||||
android:layout_marginRight="10dp"
|
||||
android:gravity="center"
|
||||
android:layout_toRightOf="@id/llyt_groupname_input_panel"
|
||||
android:text="创建" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/group_add_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/group_create_layout"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="51dp"
|
||||
android:paddingBottom="20dp">
|
||||
|
||||
<View
|
||||
android:id="@+id/line_add"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#e5e5e6" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llyt_groupid_input_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/line_add"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_group_id"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="35dp"
|
||||
android:background="#00000000"
|
||||
android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ_"
|
||||
android:ems="20"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="请输入组ID..."
|
||||
android:inputType="text"
|
||||
android:paddingLeft="5dp"
|
||||
android:singleLine="true"
|
||||
android:textSize="18sp"></EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/llyt_groupid_input_panel"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="25dp"
|
||||
android:weightSum="3">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_group_join"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="加入组" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_person_delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="删除成员" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_group_delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="删除组" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/group_mygroup_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/group_add_layout">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_group_mygroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="已创建的组"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/line_my_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:layout_below="@id/txt_group_mygroup"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#e5e5e6" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
140
src/android/sample/speechDemo/src/main/res/layout/iatdemo.xml
Normal file
@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="讯飞听写示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/image_iat_set"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/main_setting_btn_np" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/iat_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/text_show_iat_result"
|
||||
android:gravity="top|left"
|
||||
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: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:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_recognize"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_stop"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="取消"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
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"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_recognize_stream"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="音频流识别"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="上传联系人、词表,可以使云端识别联系人和词表更加准确,这里上传的内容对语义理解同样有效。"
|
||||
android:textSize="@dimen/txt_size" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_upload_contacts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="上传联系人"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/iat_upload_userwords"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="上传词表"
|
||||
android:textSize="17sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical">
|
||||
<ImageView
|
||||
android:id="@+id/ifly_mnotice_image_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</RelativeLayout>
|
100
src/android/sample/speechDemo/src/main/res/layout/isedemo.xml
Normal file
@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="讯飞评测示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/image_ise_set"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/main_setting_btn_np" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ise_eva_text"
|
||||
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" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/ise_start"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始评测"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/ise_stop"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止评测"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<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/ise_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="取消评测"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/ise_parse"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="结果解析"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="讯飞语法示例"
|
||||
android:textSize="30sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/isr_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="top|left"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<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/isr_grammar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="构建语法"
|
||||
android:textSize="20sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<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/isr_recognize"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始识别"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<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/isr_stop"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止录音"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/isr_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="取消"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
161
src/android/sample/speechDemo/src/main/res/layout/isvdemo.xml
Normal file
@ -0,0 +1,161 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="讯飞语音声纹示例"
|
||||
android:textSize="30sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/set_authId"
|
||||
android:maxLines="1"
|
||||
android:hint="请输入 authId"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_result"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="top|left"
|
||||
android:maxLines="3"
|
||||
android:minLines="3" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/isv_getpassword"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="获取密码" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/isv_search"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="查询模型" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/isv_delete"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="删除模型" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="27dp"
|
||||
android:layout_marginRight="27dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center"
|
||||
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" >
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/vocal_radioEnroll"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text=" 声纹注册"
|
||||
android:textSize="18sp" >
|
||||
</RadioButton>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/vocal_radioVerify"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text=" 1:1验证"
|
||||
android:textSize="18sp" >
|
||||
</RadioButton>
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/isv_reocrd"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始录音" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/isv_identity"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="0.1dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1:N验证" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/showPwd"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/showMsg"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/showRegFbk"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recordTime"
|
||||
style="@style/textStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/list_item_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="3dip" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/group_item_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" >
|
||||
</TextView>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/list_item_identify"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:paddingBottom="3dip" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/identify_item_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="第一:"
|
||||
android:textColor="#ebf657"
|
||||
android:textSize="20sp" />
|
||||
<TextView
|
||||
android:id="@+id/identify_item_user"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text="18505511338"
|
||||
android:textColor="#ebf657"
|
||||
android:textSize="20sp" />
|
||||
<TextView
|
||||
android:id="@+id/identify_item_score"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text="90.11%"
|
||||
android:textColor="#ebf657"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/list_bg_color"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
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>
|
30
src/android/sample/speechDemo/src/main/res/layout/main.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/layout_backgroud"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<include layout="@layout/title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/margin_"
|
||||
android:layout_marginRight="@dimen/margin_"
|
||||
android:textSize="@dimen/txt_size" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listview_main"
|
||||
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" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="在线人脸识别示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/online_img"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/no_photo" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/online_authid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:digits="abcdefghijklmnopqrstuvwxyz0123456789_"
|
||||
android:hint="请输入 authid"
|
||||
android:maxLength="18"
|
||||
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" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_pick"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="选图"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_camera"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="拍照"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_reg"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="注册"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/online_verify"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1:1验证"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_modle_delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/face_model_delete"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_identity"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1:N验证"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
16
src/android/sample/speechDemo/src/main/res/layout/title.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:gravity="center" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:gravity="center"
|
||||
android:text="讯飞语音示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
</LinearLayout>
|
124
src/android/sample/speechDemo/src/main/res/layout/ttsdemo.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="讯飞合成示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/image_tts_set"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/main_setting_btn_np" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tts_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="top|left"
|
||||
android:text="@string/text_tts_source"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
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" >
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/tts_radioCloud"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:checked="true"
|
||||
android:text="在线合成" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<Button
|
||||
android:id="@+id/tts_btn_person_select"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="发音人" />
|
||||
</LinearLayout>
|
||||
|
||||
<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/tts_play"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始合成"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/tts_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="取消"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<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/tts_pause"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="暂停播放"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/tts_resume"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="继续播放"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="讯飞语义示例"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/image_understander_set"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/main_setting_btn_np" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/understander_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="top|left"
|
||||
android:hint="@string/text_understand_hint"
|
||||
android:paddingBottom="40dp"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<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/text_understander"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="文本语义"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/start_understander"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="语音语义"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<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/understander_stop"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止录音"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/understander_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="取消"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
17
src/android/sample/speechDemo/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<!-- 画面背景色 -->
|
||||
<drawable name="layout_backgroud">#000000</drawable>
|
||||
|
||||
<!-- 分割线背景色 -->
|
||||
<drawable name="line_background">#161823</drawable>
|
||||
|
||||
<color name="white">#FFFFFF</color>
|
||||
|
||||
<!-- 控件按下时显示的颜色 -->
|
||||
<color name="list_backgroud_color">#2fb3cb</color>
|
||||
<color name="title_color">#0f8ec5</color>
|
||||
<color name="content_color">#737373</color>
|
||||
|
||||
</resources>
|
11
src/android/sample/speechDemo/src/main/res/values/dimen.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<dimen name="margin_">10dp</dimen>
|
||||
<dimen name="pading_">5dp</dimen>
|
||||
<dimen name="btn_size">22sp</dimen>
|
||||
<dimen name="txt_size">18sp</dimen>
|
||||
|
||||
<!-- 分割线高度 -->
|
||||
<dimen name="line_height">1dp</dimen>
|
||||
</resources>
|
196
src/android/sample/speechDemo/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,196 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="app_name">讯飞语音示例</string>
|
||||
<!-- 请替换成在语音云官网申请的appid -->
|
||||
<string name="app_id">5faa33ce</string>
|
||||
<string name="example_explain">本示例为讯飞语音Android平台开发者提供语音听写、语法识别、语义理解和语音合成等代码样例,旨在让用户能够依据该示例快速开发出基于语音接口的应用程序。</string>
|
||||
<string name="text_tts_source">科大讯飞作为中国最大的智能语音技术提供商,在智能语音技术领域有着长期的研究积累,并在中文语音合成、语音识别、口语评测等多项技术上拥有国际领先的成果。科大讯飞是我国唯一以语音技术为产业化方向的“国家863计划成果产业化基地”…</string>
|
||||
<string name="text_tts_source_en">iFLYTEK is a national key software enterprise dedicated to the research of intelligent speech and language technologies, development of software and chip products, provision of speech information services, and integration of E-government systems. The intelligent speech technology of iFLYTEK, the core technology of the company, represents the top level in the world.</string>
|
||||
<string name="text_isr_abnf_hint">\t上传内容为:\n\t#ABNF 1.0 gb2312;\n\tlanguage zh-CN;\n\tmode voice;\n\troot $main;\n\t$main = $place1 到$place2 ;\n\t$place1 = 北京 | 武汉 | 南京 | 天津 | 东京;\n\t$place2 = 上海 | 合肥;</string>
|
||||
<string name="text_understand_hint">\t您可以说:\n\t今天的天气怎么样?\n\t北京到上海的火车?\n\t来首歌吧?\n\n\t更多语义请登录:\n\thttp://aiui.xfyun.cn/ \n\t配置您的专属语义吧!</string>
|
||||
<!-- 听写 -->
|
||||
<string name="text_begin">请开始说话…</string>
|
||||
<string name="text_begin_recognizer">开始音频流识别</string>
|
||||
<string name="text_begin_ise">开始音频流评测</string>
|
||||
<string name="text_upload_contacts">上传联系人</string>
|
||||
<string name="text_upload_userwords">上传用户词表</string>
|
||||
<string name="text_upload_success">上传成功</string>
|
||||
<string name="text_userword_empty">词表下载失败或内容为空</string>
|
||||
<string name="text_download_success">下载成功</string>
|
||||
<string name="pref_key_iat_show">iat_show</string>
|
||||
<string name="pref_title_iat_show">显示听写界面</string>
|
||||
<string name="text_show_contacts">上传联系人/词表显示</string>
|
||||
<string name="text_show_iat_result">听写结果显示</string>
|
||||
|
||||
<string name="pref_key_translate">translate</string>
|
||||
<string name="pref_title_translate">翻译</string>
|
||||
|
||||
<string name="face_model_delete">人脸模型删除</string>
|
||||
|
||||
<string name="title_face_idf">人脸1:N检索示例</string>
|
||||
<string name="title_vocal_idf">声纹1:N检索示例</string>
|
||||
|
||||
|
||||
<!-- 合成 -->
|
||||
<string-array name="engine_entries">
|
||||
<item>本地合成</item>
|
||||
<item>在线合成</item>
|
||||
</string-array>
|
||||
<string-array name="engine_values">
|
||||
<item>local</item>
|
||||
<item>cloud</item>
|
||||
</string-array>
|
||||
<string-array name="voicer_cloud_entries">
|
||||
<item>小燕—女青、中英、普通话</item>
|
||||
<item>小宇—男青、中英、普通话</item>
|
||||
<item>凯瑟琳—女青、英</item>
|
||||
<item>亨利—男青、英</item>
|
||||
<item>玛丽—女青、英</item>
|
||||
<item>小研—女青、中英、普通话</item>
|
||||
<item>小琪—女青、中英、普通话</item>
|
||||
<item>小峰—男青、中英、普通话</item>
|
||||
<item>小梅—女青、中英、粤语</item>
|
||||
<item>小莉—女青、中英、台湾普通话</item>
|
||||
<item>小蓉—女青、中、四川话</item>
|
||||
<item>小芸—女青、中、东北话</item>
|
||||
<item>小坤—男青、中、河南话</item>
|
||||
<item>小强—男青、中、湖南话</item>
|
||||
<item>小莹—女青、中、陕西话</item>
|
||||
<item>小新—男童、中、普通话</item>
|
||||
<item>楠楠—女童、中、普通话</item>
|
||||
<item>老孙—男老、中、普通话</item>
|
||||
</string-array>
|
||||
<string-array name="voicer_cloud_values">
|
||||
<item>xiaoyan</item>
|
||||
<item>xiaoyu</item>
|
||||
<item>catherine</item>
|
||||
<item>henry</item>
|
||||
<item>vimary</item>
|
||||
<item>vixy</item>
|
||||
<item>xiaoqi</item>
|
||||
<item>vixf</item>
|
||||
<item>xiaomei</item>
|
||||
<item>xiaolin</item>
|
||||
<item>xiaorong</item>
|
||||
<item>xiaoqian</item>
|
||||
<item>xiaokun</item>
|
||||
<item>xiaoqiang</item>
|
||||
<item>vixying</item>
|
||||
<item>xiaoxin</item>
|
||||
<item>nannan</item>
|
||||
<item>vils</item>
|
||||
</string-array>
|
||||
<string-array name="emot_entries">
|
||||
<item>正常</item>
|
||||
<item>高兴</item>
|
||||
<item>悲伤</item>
|
||||
<item>生气</item>
|
||||
</string-array>
|
||||
<string-array name="emot_values">
|
||||
<item>neutral</item>
|
||||
<item>happy</item>
|
||||
<item>sad</item>
|
||||
<item>angry</item>
|
||||
</string-array>
|
||||
<string-array name="stream_entries">
|
||||
<item>通话</item>
|
||||
<item>系统</item>
|
||||
<item>铃声</item>
|
||||
<item>音乐</item>
|
||||
<item>闹铃</item>
|
||||
<item>通知</item>
|
||||
</string-array>
|
||||
<string-array name="stream_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
<string formatted="false" name="tts_toast_format">缓冲进度为%d%%,播放进度为%d%%</string>
|
||||
<!-- 语言 -->
|
||||
<string-array name="language_entries">
|
||||
<item>普通话</item>
|
||||
<item>粤语</item>
|
||||
<item>英语</item>
|
||||
</string-array>
|
||||
<string-array name="language_values">
|
||||
<item>mandarin</item>
|
||||
<item>cantonese</item>
|
||||
<item>en_us</item>
|
||||
</string-array>
|
||||
<!-- 语音评测 -->
|
||||
<string name="text_en_word">"[word]\napple\nbanana\norange"</string>
|
||||
<string name="text_en_sentence">"The quick brown fox jumps over the lazy dog."</string>
|
||||
<string name="text_cn_syllable">"知,痴,是"</string>
|
||||
<string name="text_cn_word">"磁铁,率领,脆弱,动手,古筝"</string>
|
||||
<string name="text_cn_sentence">"一座座雪峰插入云霄,峰顶银光闪闪,大大小小的湖泊,像颗颗宝石镶嵌在彩带般的沟谷中。"</string>
|
||||
<string-array name="ise_language_entries">
|
||||
<item>英语</item>
|
||||
<item>汉语</item>
|
||||
</string-array>
|
||||
<string-array name="ise_language_values">
|
||||
<item>en_us</item>
|
||||
<item>zh_cn</item>
|
||||
</string-array>
|
||||
<string-array name="category_entries">
|
||||
<item>单字</item>
|
||||
<item>词语</item>
|
||||
<item>句子</item>
|
||||
</string-array>
|
||||
<string-array name="category_values">
|
||||
<item>read_syllable</item>
|
||||
<item>read_word</item>
|
||||
<item>read_sentence</item>
|
||||
</string-array>
|
||||
<string-array name="result_level_entries">
|
||||
<item>plain</item>
|
||||
<item>complete</item>
|
||||
</string-array>
|
||||
<!-- 标点符号 -->
|
||||
<string-array name="punc_entries">
|
||||
<item>有标点</item>
|
||||
<item>无标点</item>
|
||||
</string-array>
|
||||
<string-array name="punc_values">
|
||||
<item>1</item>
|
||||
<item>0</item>
|
||||
</string-array>
|
||||
<string-array name="dwa_entries">
|
||||
<item>开启</item>
|
||||
<item>关闭</item>
|
||||
</string-array>
|
||||
<string-array name="iat_language_entries">
|
||||
<item>中文</item>
|
||||
<item>英语</item>
|
||||
<item>日语</item>
|
||||
<item>俄语</item>
|
||||
<item>西班牙语</item>
|
||||
<item>法语</item>
|
||||
<item>韩语</item>
|
||||
</string-array>
|
||||
<string-array name="iat_language_value">
|
||||
<item>zh_cn</item>
|
||||
<item>en_us</item>
|
||||
<item>ja_jp</item>
|
||||
<item>ru-ru</item>
|
||||
<item>es_es</item>
|
||||
<item>fr_fr</item>
|
||||
<item>ko_kr</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
<!-- 语言 -->
|
||||
<string-array name="machine_entries">
|
||||
<item>鲁谷</item>
|
||||
<item>广州</item>
|
||||
<item>森华</item>
|
||||
</string-array>
|
||||
<string-array name="machine_values">
|
||||
<item>http://bj.voicecloud.cn/msp.do</item>
|
||||
<item>http://gz.voicecloud.cn/msp.do</item>
|
||||
<item>http://dx.xf-yun.com/msp.do</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
17
src/android/sample/speechDemo/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?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>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:background">@android:color/transparent</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
<item name="android:backgroundDimAmount">0.6</item>
|
||||
</style>
|
||||
|
||||
<style name="textStyle">
|
||||
<item name="android:textSize">16sp</item>
|
||||
</style>
|
||||
</resources>
|
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<ListPreference
|
||||
android:key="iat_language_preference"
|
||||
android:title="语言设置"
|
||||
android:entries="@array/language_entries"
|
||||
android:entryValues="@array/language_values"
|
||||
android:summary="支持:普通话,粤语,英语 "
|
||||
android:defaultValue="mandarin" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="iat_vadbos_preference"
|
||||
android:title="前端点超时"
|
||||
android:dialogTitle="请输入时间(0-10000)ms"
|
||||
android:summary="默认值:短信转写5000,其他4000"
|
||||
android:defaultValue="5000" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="iat_vadeos_preference"
|
||||
android:title="后端点超时"
|
||||
android:dialogTitle="请输入时间(0-10000)ms"
|
||||
android:summary="默认值:短信转写1800,其他700 "
|
||||
android:defaultValue="1800" />
|
||||
|
||||
<ListPreference
|
||||
android:key="iat_punc_preference"
|
||||
android:title="标点符号"
|
||||
android:entries="@array/punc_entries"
|
||||
android:entryValues="@array/punc_values"
|
||||
android:summary="默认值:有标点 "
|
||||
android:defaultValue="1" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="@string/pref_key_iat_show"
|
||||
android:title="@string/pref_title_iat_show"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceScreen>
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<ListPreference
|
||||
android:key="language"
|
||||
android:title="评测语种"
|
||||
android:summary=""
|
||||
android:entries="@array/ise_language_entries"
|
||||
android:entryValues="@array/ise_language_values"
|
||||
android:defaultValue="zh_cn"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="category"
|
||||
android:title="评测题型"
|
||||
android:summary=""
|
||||
android:entries="@array/category_entries"
|
||||
android:entryValues="@array/category_values"
|
||||
android:defaultValue="read_sentence"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="result_level"
|
||||
android:title="结果等级"
|
||||
android:summary=""
|
||||
android:entries="@array/result_level_entries"
|
||||
android:entryValues="@array/result_level_entries"
|
||||
android:defaultValue="complete"/>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="vad_bos"
|
||||
android:title="前端点超时"
|
||||
android:summary=""
|
||||
android:defaultValue="5000"/>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="vad_eos"
|
||||
android:title="后端点超时"
|
||||
android:summary=""
|
||||
android:defaultValue="1800"/>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="speech_timeout"
|
||||
android:title="评测超时"
|
||||
android:summary=""
|
||||
android:defaultValue="-1"/>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<EditTextPreference
|
||||
android:dialogTitle="请输入语速:在线(0-100)本地(0-200)"
|
||||
android:key="speed_preference"
|
||||
android:defaultValue="50"
|
||||
android:summary="默认值:50 "
|
||||
android:title="语速" />
|
||||
<EditTextPreference
|
||||
android:dialogTitle="请输入音调(0-100)"
|
||||
android:key="pitch_preference"
|
||||
android:defaultValue="50"
|
||||
android:summary="默认值:50 "
|
||||
android:title="音调" />
|
||||
<EditTextPreference
|
||||
android:dialogTitle="请输入音量(0-100)"
|
||||
android:key="volume_preference"
|
||||
android:defaultValue="50"
|
||||
android:summary="默认值:50 "
|
||||
android:title="音量" />
|
||||
<ListPreference
|
||||
android:defaultValue="3"
|
||||
android:entries="@array/stream_entries"
|
||||
android:entryValues="@array/stream_values"
|
||||
android:key="stream_preference"
|
||||
android:title="音频流类型" />
|
||||
|
||||
</PreferenceScreen>
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<ListPreference
|
||||
android:key="understander_language_preference"
|
||||
android:title="语言设置"
|
||||
android:entries="@array/language_entries"
|
||||
android:entryValues="@array/language_values"
|
||||
android:summary="支持:普通话,粤语,英语 "
|
||||
android:defaultValue="mandarin" />
|
||||
<EditTextPreference
|
||||
android:key="understander_vadbos_preference"
|
||||
android:title="前端点超时"
|
||||
android:dialogTitle="请输入时间(0-10000)ms"
|
||||
android:summary="默认值:短信转写5000,其他4000"
|
||||
android:defaultValue="4000" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="understander_vadeos_preference"
|
||||
android:title="后端点超时"
|
||||
android:dialogTitle="请输入时间(0-10000)ms"
|
||||
android:summary="默认值:短信转写1800,其他700 "
|
||||
android:defaultValue="700" />
|
||||
|
||||
<ListPreference
|
||||
android:key="understander_punc_preference"
|
||||
android:title="标点符号"
|
||||
android:entries="@array/punc_entries"
|
||||
android:entryValues="@array/punc_values"
|
||||
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" /> -->
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<ListPreference
|
||||
android:key="url_preference"
|
||||
android:title="域名设置"
|
||||
android:entries="@array/machine_entries"
|
||||
android:entryValues="@array/machine_values"
|
||||
android:summary="支持:鲁谷,广州,森华 " />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="url_edit"
|
||||
android:title="输入域名(优先级较高) 格式参考:域名(+:端口)"
|
||||
android:summary=""/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@ -34,6 +34,7 @@
|
||||
NSLog(@"error: IFlySpeechConfig.plist not found");
|
||||
assert(0);
|
||||
}
|
||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||
self.appId = [plistData valueForKey:@"AppKey"];
|
||||
}
|
||||
|
||||
@ -42,10 +43,6 @@
|
||||
|
||||
}
|
||||
|
||||
- (void) loadAppID{
|
||||
|
||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||
}
|
||||
|
||||
#pragma mark - 语音录入
|
||||
- (void)startListening:(CDVInvokedUrlCommand*)command
|
||||
|
24
src/ios/iflyMSC.framework/Headers/IFlyContact.h
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// IFlyContact.h
|
||||
// msc
|
||||
//
|
||||
// Created by ypzhao on 13-3-1.
|
||||
// Copyright (c) 2013年 IFLYTEK. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/*!
|
||||
* 此接口为获取通信录中的联系人。<br>
|
||||
* 获取联系人是为了在进行语音识别时(sms)能更好的识别出您说的人名,联系人上传是属于个性化的一部分。
|
||||
*/
|
||||
@interface IFlyContact : NSObject
|
||||
|
||||
/*!
|
||||
* 获取联系人。<br>
|
||||
* 调用此方法需要添加 AddressBook.framework 和 Contacts.framework到工程中,调用此方法后可以直接将通信录中的联系人转化为语音云识别的数据结构。您可以将获取的数据通过IFlyDataUploader类,上传到语音云,我们只获取通信录中的人名。
|
||||
*
|
||||
* @return 返回联系人信息
|
||||
*/
|
||||
- (NSString *) contact;
|
||||
@end
|
37
src/ios/iflyMSC.framework/Headers/IFlyIdentityResult.h
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// IFlyIdentityResult.h
|
||||
// IFlyMSC
|
||||
//
|
||||
// Created by 张剑 on 15/5/14.
|
||||
// Copyright (c) 2015年 iflytek. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* 身份验证结果类
|
||||
*/
|
||||
@interface IFlyIdentityResult : NSObject
|
||||
|
||||
/**
|
||||
* json字符串格式结果
|
||||
*/
|
||||
@property(nonatomic,retain)NSString* result;
|
||||
|
||||
/**
|
||||
* 创建身份验证结果类实例
|
||||
*
|
||||
* @param jsonString json字符串
|
||||
*
|
||||
* @return 身份验证结果类实例
|
||||
*/
|
||||
+(instancetype)identityResultWithString:(NSString*)jsonString;
|
||||
|
||||
/**
|
||||
* 返回字典格式的结果
|
||||
*
|
||||
* @return 字典格式的结果
|
||||
*/
|
||||
-(NSDictionary*)dictionaryResults;
|
||||
|
||||
@end
|
176
src/ios/iflyMSC.framework/Headers/IFlyIdentityVerifier.h
Normal file
@ -0,0 +1,176 @@
|
||||
//
|
||||
// IFlyIdentityVerifier.h
|
||||
// IFlyMSC
|
||||
//
|
||||
// Created by 张剑 on 15/4/22.
|
||||
// Copyright (c) 2015年 iflytek. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "IFlyIdentityVerifierDelegate.h"
|
||||
|
||||
/**
|
||||
* 身份验证功能类
|
||||
*/
|
||||
@interface IFlyIdentityVerifier : NSObject
|
||||
|
||||
/*!
|
||||
* 设置委托对象
|
||||
*/
|
||||
@property (nonatomic, assign) id <IFlyIdentityVerifierDelegate> delegate;
|
||||
|
||||
/**
|
||||
* 返回身份验证对象的单例
|
||||
*
|
||||
* @return 身份验证对象的单例
|
||||
*/
|
||||
+ (instancetype) sharedInstance;
|
||||
|
||||
/**
|
||||
* 销毁身份验证对象单例。
|
||||
*
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
+ (void)purgeSharedInstance;
|
||||
|
||||
/**
|
||||
* 设置参数
|
||||
*
|
||||
* @param value 参数值
|
||||
* @param key 参数名
|
||||
*
|
||||
* @return 设置的参数和取值正确返回YES,失败返回NO
|
||||
*/
|
||||
- (BOOL)setParameter:(NSString *)value forKey:(NSString *)key;
|
||||
|
||||
/**
|
||||
* 开始会话
|
||||
* 在这之后会开始各项业务。
|
||||
*/
|
||||
- (void)startWorking;
|
||||
|
||||
/*
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | ifr 参数 | 描述
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | data_format |数据格式:即图片格式,支持jpg(默认),gif
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | data_encoding |数据压缩编码:即图片压缩编码,支持raw(不压缩,默认值)
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | wtt |等待超时时间: 支持大于0的整数,默认为3000ms
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | ivp 参数 | 描述
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | rgn |训练次数:取值2~9.无默认值,必须明确指定。
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | |声纹确认门限值,验证得分>=tsd验证通过,否则验证失败(该参数目前不支持,
|
||||
* | tsd |作为保留参数。)却只范围:0~100.
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | ptxt |密码文本。从服务端下载,比如数字密码所需要的数字串。
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | pwdt |密码类型。取值:1(文本密码),2(自由说),3(数字密码).
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | fin |取消注册。取值:0(不取消,即不生效),1(取消本次注册).
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | wtt |等待超时时间:描述客户端等待结果的超时时间
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | vad_enable |VAD功能开关。是否启用VAD处理,取值:1(开启,默认),0(不开启)。
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | |头部静音最大长度。如果静音长度超过此值,则认为用户此次无有效音频输入。
|
||||
* | vad_bos |此参数仅在打开VAD功能时生效。(云端暂时没有)。取值:0~30000ms,
|
||||
* | |默认为10000ms
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | |尾部静音长度。如果尾部静音长度超过了此值,则认为音频已经结束。
|
||||
* | |此参数仅在打开VAD功能时生效。(云端暂时没有)。取值:0~30000ms,
|
||||
* | vad_eos |默认为2000ms
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | data_encoding |数据压缩编码,音频压缩编码。
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | data_format |在声纹业务中为音频采样率,取值:16000(默认),8000
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | ipt 参数 | 描述
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | scope |操作范围 person,group
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | group_id |指定鉴别的组数字或者字符串,唯一值 不为空
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | |组名称 “”或者不能包含^@,&=*'"等非法字符,且长度不得超过255.
|
||||
* | group_name |此参数可以为空,对于group_name约束不在云端控制,由前段控制
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
* | topc |[top candidates],返回得分最高的候选人数目 取值1-5 默认是1.
|
||||
* | | 可以开放由用户设置,最大topc值为5
|
||||
* | ------------- |-----------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 写入子业务数据、或者进行模型操作、下载密码。
|
||||
*
|
||||
* @param ssub 子业务名
|
||||
* @param data 数据
|
||||
* @param offset 偏移量
|
||||
* @param length 长度
|
||||
* @param params 参数
|
||||
* <table>
|
||||
* <thead>
|
||||
* <tr><th>*ifr参数</th><th><em>描述</em></th></tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr><td>data_format</td><td>数据格式:即图片格式,支持jpg(默认),gif</td></tr>
|
||||
* <tr><td>data_encoding</td><td>数据压缩编码:即图片压缩编码,支持raw(不压缩,默认值)</td></tr>
|
||||
* <tr><td>wtt</td><td>等待超时时间: 支持大于0的整数,默认为3000ms</td></tr>
|
||||
* </tbody>
|
||||
* <thead>
|
||||
* <tr><th>*ivp参数</th><th><em>描述</em></th></tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr><td>rgn</td><td>训练次数:取值2~9.无默认值,必须明确指定。</td></tr>
|
||||
* <tr><td>tsd</td><td>声纹确认门限值,验证得分>=tsd验证通过,否则验证失败(该参数目前不支持,作为保留参数。)却只范围:0~100.</td></tr>
|
||||
* <tr><td>ptxt</td><td>密码文本。从服务端下载,比如数字密码所需要的数字串。</td></tr>
|
||||
* <tr><td>pwdt</td><td>密码类型。取值:1(文本密码),2(自由说),3(数字密码).</td></tr>
|
||||
* <tr><td>fin</td><td>取消注册。取值:0(不取消,即不生效),1(取消本次注册).</td></tr>
|
||||
* <tr><td>wtt</td><td>等待超时时间:描述客户端等待结果的超时时间.</td></tr>
|
||||
* <tr><td>vad_enable</td><td>VAD功能开关。是否启用VAD处理,取值:1(开启,默认),0(不开启)。</td></tr>
|
||||
* <tr><td>vad_bos</td><td>头部静音最大长度。如果静音长度超过此值,则认为用户此次无有效音频输入。</br>此参数仅在打开VAD功能时生效。(云端暂时没有)。</br>取值:0~30000ms,默认为10000ms</td></tr>
|
||||
* <tr><td>vad_eos</td><td>尾部静音长度。如果尾部静音长度超过了此值,则认为音频已经结束。</br>此参数仅在打开VAD功能时生效。(云端暂时没有)。</br>取值:0~30000ms,默认为2000ms</td></tr>
|
||||
* <tr><td>data_encoding</td><td>数据压缩编码,音频压缩编码。</td></tr>
|
||||
* <tr><td>data_format</td><td>在声纹业务中为音频采样率,取值:16000(默认),8000</td></tr>
|
||||
* </tbody>
|
||||
* <thead>
|
||||
* <tr><th>*ipt参数</th><th><em>描述</em></th></tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr><td>scope</td><td>操作范围 person,group</td></tr>
|
||||
* <tr><td>group_id</td><td>指定鉴别的组数字或者字符串,唯一值 不为空</td></tr>
|
||||
* <tr><td>group_name</td><td>组名称 “”或者不能包含^@,&=*'"等非法字符,且长度不得超过255.此参数可以为空,对于group_name约束不在云端控制,由前段控制</td></tr>
|
||||
* <tr><td>topc</td><td>组名称[top candidates],返回得分最高的候选人数目 取值1-5 默认是1.可以开放由用户设置,最大topc值为5</td></tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*/
|
||||
-(void)write:(NSString*)ssub data:(NSData*)data offset:(int)offset length:(int)length withParams:(NSString*)params;
|
||||
|
||||
/**
|
||||
* 停止子业务数据写入
|
||||
*
|
||||
* @param ssub 子业务名:ivp,ifr,ipt
|
||||
*/
|
||||
-(void)stopWrite:(NSString*)ssub;
|
||||
|
||||
/**
|
||||
* 执行模型查询、删除和声纹密码下载等操作
|
||||
* *注意此方法不能与startWorking方法同时使用。
|
||||
*
|
||||
* @param ssub 子业务类型、可选值:ivp(声纹)、ifr(人脸)、ipt(鉴别)
|
||||
* @param cmd 操作命令,可选值:query、delete、download、add
|
||||
* @param params 子业务参数,参见write:data:offset:length:withParams:
|
||||
*/
|
||||
-(void)execute:(NSString*)ssub cmd:(NSString*)cmd params:(NSString*)params;
|
||||
|
||||
/**
|
||||
* 取消本次会话
|
||||
*/
|
||||
- (void)cancel;
|
||||
|
||||
@end
|
||||
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// IFlyIdentityVerifierDelegate.h
|
||||
// IFlyMSC
|
||||
//
|
||||
// Created by 张剑 on 15/4/22.
|
||||
// Copyright (c) 2015年 iflytek. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class IFlySpeechError;
|
||||
@class IFlyIdentityResult;
|
||||
|
||||
/**
|
||||
* 身份验证功能类回调
|
||||
*/
|
||||
@protocol IFlyIdentityVerifierDelegate <NSObject>
|
||||
|
||||
/*!
|
||||
* 错误回调
|
||||
*
|
||||
* @param error 错误描述类
|
||||
*/
|
||||
- (void)onCompleted:(IFlySpeechError *)error;
|
||||
|
||||
/*!
|
||||
* 结果回调
|
||||
*
|
||||
* @param results -[out] 结果。
|
||||
* @param isLast -[out] 是否最后一条结果
|
||||
*/
|
||||
- (void)onResults:(IFlyIdentityResult *)results isLast:(BOOL)isLast;
|
||||
|
||||
/**
|
||||
* 扩展接口,用于抛出音量和vad_eos消息
|
||||
*
|
||||
* @param eventType 消息类型
|
||||
* @param arg1 eventType为 Event_volume 时 arg1为音量值
|
||||
* @param arg2 参数2
|
||||
* @param obj 扩展参数
|
||||
*/
|
||||
- (void)onEvent:(int)eventType arg1:(int)arg1 arg2:(int)arg2 extra:(id)obj;
|
||||
|
||||
@end
|
||||
|
@ -12,6 +12,9 @@
|
||||
#import "IFlyAudioSession.h"
|
||||
#import "IFlyDataUploader.h"
|
||||
#import "IFlyDebugLog.h"
|
||||
#import "IFlyIdentityVerifier.h"
|
||||
#import "IFlyIdentityResult.h"
|
||||
#import "IFlyIdentityVerifierDelegate.h"
|
||||
#import "IFlyISVDelegate.h"
|
||||
#import "IFlyISVRecognizer.h"
|
||||
#import "IFlyRecognizerView.h"
|
||||
@ -30,9 +33,8 @@
|
||||
#import "IFlySpeechUtility.h"
|
||||
#import "IFlyUserWords.h"
|
||||
#import "IFlyPcmRecorder.h"
|
||||
#import "IFlyVerifierUtil.h"
|
||||
#import "IFlyVoiceWakeuper.h"
|
||||
#import "IFlyVoiceWakeuperDelegate.h"
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|