package com.dear.smb.smb_demo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.dear.smb.android.api.CallBackResult;
import com.dear.smb.android.api.NameValuePair;
import com.dear.smb.android.api.SMBAPIConstant;
import com.dear.smb.android.api.TrainerCallBack;
import com.dear.voice.IRecordListener;
import com.dear.voice.VoiceFormat;
import com.dear.voice.VoiceRecorder;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
public class TrainerActivity extends Activity {
private VoiceRecorder voiceRecorder;//声明录音 工具类对象
private TextView mNumberTV, mVervif_prompt;
private Button mMicBtn;
private byte[] recordData ;
private String SessionId ;
private int Index = 0 ;
private String[] traintext = new String[5] ;
private NameValuePair nameValuePair = new NameValuePair() ;
private TrainerCallBack trainerCallBack ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trainer);
initView() ;
initSmbController() ;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
initRecordTools() ;
}
protected void showToast(Context context, String msg) {
Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL,
0, 0);
toast.show();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (voiceRecorder != null) {
voiceRecorder.releaseRecord();//释放录音资源
voiceRecorder = null ;
}
}
private void initSmbController() {
trainerCallBack = new TrainerCallBack(this) {
@Override
public void onSuccess(CallBackResult callBackResult) {
super.onSuccess(callBackResult);
switch (callBackResult.getTag()) {
case 1:
//getTextSuccess
ProgressDialogUtils.dismissProgressDialog();
String temp = callBackResult.getTrainerTextResult().getText() ;
int interval = callBackResult.getTrainerTextResult().getInterval() ;
SessionId = callBackResult.getTrainerTextResult().getSessionId() ;
JsonArray object = new JsonParser().parse(temp).getAsJsonArray();
traintext = new String[5];
for (int i = 0; i < 5; i++) {
traintext[i] = object.get(i).toString().replaceAll("\"", "");
}
mNumberTV.setText(traintext[Index]);
break;
case 2:
//UploadVoiceSuccess
ProgressDialogUtils.dismissProgressDialog();
int index = callBackResult.getTrainerUploadVoiceResult().getIndex();
showToast(getApplicationContext(), "第"+index+"条语音上传成功!");
SessionId = callBackResult.getTrainerUploadVoiceResult().getSessionId() ;
if(index == 5 ){
ProgressDialogUtils.showProgressDialog(TrainerActivity.this , "建模中...");
nameValuePair.setSessionId(SessionId);
nameValuePair.setVoiceprintId(Constant.HttpCode.USERNAME);
trainerCallBack.executeTrainer(nameValuePair);
return ;
}
Index++ ;
mNumberTV.setText(traintext[Index]);
break;
case 3:
//TrainerSucccess
ProgressDialogUtils.dismissProgressDialog();
String VoiceprintID = callBackResult.getTrainerResult().getVoiceprintId() ;
showToast(getApplicationContext(), "建模成功!ID:"+VoiceprintID);
System.out.println("VoiceprintID:"+VoiceprintID);
SharedPreferencesUtils.setParam(getApplicationContext(), "voiceprintID", VoiceprintID);
finish();
break;
default:
break;
}
}
@Override
public void onFailure(int exceptionMsg) {
// TODO Auto-generated method stub
super.onFailure(exceptionMsg);
ProgressDialogUtils.dismissProgressDialog();
if(ErrorEscape.errorTrans_train(exceptionMsg)!=null){
showToast(getApplicationContext(), ErrorEscape.errorTrans_train(exceptionMsg));
}else{
showToast(getApplicationContext(), "服务端异常!("+exceptionMsg+")");
finish();
}
}
};
ProgressDialogUtils.showProgressDialog(this, "获取建模文本...");
nameValuePair.setTrainType(SMBAPIConstant.TEXT_TYPE_TRAINING_8_5);
nameValuePair.setVoiceprintId(Constant.HttpCode.USERNAME);
nameValuePair.setDeviceInfo("");
trainerCallBack.executeGetText(nameValuePair);
}
OnTouchListener touchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int btn_id = v.getId();
if (btn_id == R.id.btn_mic) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
voiceRecorder.startRecord();//开始录音
mVervif_prompt.setText(getString(R.string.loosen_end));
mMicBtn.setBackgroundResource(R.drawable.mic_down);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mVervif_prompt.setText(getString(R.string.pass_say));
mMicBtn.setBackgroundResource(R.drawable.mic_up);
voiceRecorder.stopRecord();//停止录音
recordData = voiceRecorder.getRecordData() ;//获取录音数据,只可get一次,第二次为null
ProgressDialogUtils.showProgressDialog(TrainerActivity.this, "上传语音中...");
nameValuePair.setSessionId(SessionId);
nameValuePair.setIndex(Index);
nameValuePair.setDate(recordData);
trainerCallBack.executeUploadVoice(nameValuePair);
return true;
}
}
return false;
}
};
private void initRecordTools() {
// TODO Auto-generated method stub
mMicBtn.setOnTouchListener(touchListener);
//初始化录音工具类
if (voiceRecorder == null) {
// 16K 16比特 单声道 pcm编码
voiceRecorder = new VoiceRecorder(getApplicationContext(), VoiceFormat.AUDIOFORMAT_16K16BIT_MONO);
}
voiceRecorder.setRecordListener(recordListener,15L);//设置监听器
}
private void initView() {
// TODO Auto-generated method stub
mNumberTV = (TextView) findViewById(R.id.tv_verify_number);
mVervif_prompt = (TextView) findViewById(R.id.vervif_prompt);
mMicBtn = (Button) findViewById(R.id.btn_mic);
}
// 监听器
IRecordListener record
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
声纹识别,可识别说话人身份和辨别说话人,安卓语言 转载自:https://download.csdn.net/download/tingjiejie1314/10829726?utm_medium=distribute.pc_aggpage_search_result.none-task-download-2~download~first_rank_v2~rank_v25-1-10829726.nonecase&utm_term=java%E5%A3%B0%E7%BA%B9%E8%AF%86%E5%88%AB%E7%A8%8B%E5%BA%8F
资源推荐
资源详情
资源评论
收起资源包目录
安卓声纹识别源码(android) (112个子文件)
gradlew.bat 2KB
fileSnapshots.bin 4.91MB
fileHashes.bin 218KB
taskArtifacts.bin 147KB
localClassSetAnalysis.bin 58KB
localClassSetAnalysis.bin 41KB
fileSnapshotsToTreeSnapshotsIndex.bin 29KB
localJarClasspathSnapshot.bin 23KB
localJarClasspathSnapshot.bin 19KB
.DS_Store 6KB
.DS_Store 6KB
.gitignore 127B
.gitignore 8B
build.gradle 1KB
build.gradle 521B
settings.gradle 16B
gradlew 5KB
app.iml 11KB
SMB-Demo.iml 862B
AndroidDemo.iml 501B
gson-2.2.2.jar 185KB
dear-smb-sdk-2.1.0.jar 81KB
gradle-wrapper.jar 52KB
d-ear-voice-recorder-0.1.0.jar 6KB
TrainerActivity.java 8KB
VerifierActivity.java 7KB
HomeActivity.java 7KB
IpActivity.java 6KB
SharedPreferencesUtils.java 3KB
ErrorEscape.java 2KB
ProgressDialogUtils.java 684B
Constant.java 416B
cache.properties.lock 17B
localJarClasspathSnapshot.lock 17B
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis.lock 17B
localClassSetAnalysis.lock 17B
mic_down.png 163KB
mic_up.png 160KB
logo.png 62KB
ic_launcher.png 10KB
ic_launcher.png 8KB
ic_launcher.png 7KB
ic_launcher.png 5KB
ic_launcher.png 2KB
login_error_icon.png 2KB
mm_title_back_focused.9.png 2KB
mm_title_back_pressed.9.png 1KB
mm_title_back_normal.9.png 1KB
btn_style_one_normal.9.png 1KB
btn_style_one_focused.9.png 1KB
btn_style_one_pressed.9.png 1KB
btn_style_one_disabled.9.png 1KB
login_edit_pressed.9.png 531B
login_edit_normal.9.png 496B
title_bar.png 251B
proguard-rules.pro 678B
gradle.properties 747B
local.properties 444B
gradle-wrapper.properties 233B
cache.properties 31B
Satisfy-Regular.ttf 47KB
workspace.xml 149KB
workspace.xml 31KB
login.xml 7KB
misc.xml 2KB
activity_home.xml 2KB
activity_trainer.xml 2KB
activity_verifier.xml 2KB
AndroidManifest.xml 2KB
support_v4_23_4_0.xml 919B
appcompat_v7_23_4_0.xml 777B
activity_main.xml 758B
runner_0_5.xml 743B
rules_0_5.xml 737B
exposed_instrumentation_api_publish_0_5.xml 716B
gradle.xml 708B
espresso_idling_resource_2_2_2.xml 698B
compiler.xml 686B
animated_vector_drawable_23_4_0.xml 661B
btn_style_green.xml 656B
support_vector_drawable_23_4_0.xml 656B
espresso_core_2_2_2.xml 643B
runConfigurations.xml 564B
support_annotations_23_4_0.xml 527B
hamcrest_core_1_3.xml 526B
junit_4_12.xml 477B
title_btn_back.xml 472B
misc.xml 452B
login_editbox.xml 429B
Project_Default.xml 418B
styles.xml 394B
dimens.xml 364B
javax_annotation_api_1_2.xml 358B
hamcrest_integration_1_3.xml 354B
modules.xml 353B
hamcrest_library_1_3.xml 342B
jsr305_2_0_1.xml 330B
javawriter_2_1_1.xml 330B
javax_inject_1.xml 324B
共 112 条
- 1
- 2
资源评论
- ༄ེེུ星空2021-10-07不行,没有任何说明,技术落后
weixin_45229612
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- VSc++编程助手1.0 - 1
- 基于matlab的说话人语音识别源码+PPT+报告(优质项目).zip
- 语音识别基于matlab说话人识别系统源码+报告PPT(高分优质项目).zip
- 毕业设计: 校园失物招领小程序的设计与实现论文(源码 + 数据库 + 说明文档)
- 美易ME-DUI自绘模块3.3-易语言模块
- 毕业设计:小程序消防知识每天学(源码 + 数据库 + 说明文档)
- 2024-NEW.zip
- 软件.zip
- 华为FPGA设计技巧FPGA设计规范设计经验设计流程指南华为面经硬件工程师手册等资料(15个).zip
- 毕业设计:基于微信小程序大学校园二手教材与书籍拍卖系统(源码 + 数据库 + 说明文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功