新增异常处理机制,页面语音设置,网络设置
This commit is contained in:
@ -32,9 +32,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.AboutActivity"
|
||||
android:label="@string/activity_about" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -1,12 +1,141 @@
|
||||
<html lang="zh-CN">
|
||||
<p id='p'>hello world</p>
|
||||
<button onclick="VoiceEngine.startSpeaking('js调用安卓方法!')">调用安卓方法</button>
|
||||
|
||||
<script>
|
||||
function render(result){
|
||||
result+="<br/>"
|
||||
document.getElementById("p").innerHTML += result
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="keywords" content=""/>
|
||||
<meta name="description" content=""/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
|
||||
<meta name="format-detection" content="telephone=no"/>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="author" content="CSS5, css5.com.cn"/>
|
||||
<style>
|
||||
html, body {
|
||||
font-family: "Microsoft YaHei", Arial;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
background: #f7f8fa;
|
||||
color: #555;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.context {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
flex-direction: column;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.net {
|
||||
margin: 10px;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.net-list {
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.net-list label {
|
||||
width: 110px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.net-list input {
|
||||
border: 0;
|
||||
flex: 1;
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #323233;
|
||||
line-height: inherit;
|
||||
text-align: left;
|
||||
background-color: transparent;
|
||||
resize: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.net-list input:focus {
|
||||
outline: -webkit-focus-ring-color auto 0px;
|
||||
}
|
||||
|
||||
.operation {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.operation button {
|
||||
margin: 10px;
|
||||
border-radius: 5000px;
|
||||
height: 40px;
|
||||
border: 0;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.operation button:focus {
|
||||
outline: -webkit-focus-ring-color auto 0px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
<script>
|
||||
function saveSetting(){
|
||||
var data=JSON.stringify({
|
||||
"address":document.getElementById('address').value,
|
||||
"port":document.getElementById('port').value,
|
||||
"path":document.getElementById('path').value
|
||||
});
|
||||
window.NetworkSettingEngine.save(data);
|
||||
window.View.reload();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="context">
|
||||
<div class="main">
|
||||
<div class="net">
|
||||
<div class="net-list">
|
||||
<label>服务器地址</label>
|
||||
<input id="address" name="address" placeholder="ip地址或者域名地址">
|
||||
</div>
|
||||
<div class="net-list">
|
||||
<label>服务器端口号</label>
|
||||
<input value="-1" id="port" name="port" placeholder="服务器端口号">
|
||||
</div>
|
||||
<div class="net-list">
|
||||
<label>访问子路径</label>
|
||||
<input id="path" name="path" placeholder="访问子路径">
|
||||
</div>
|
||||
</div>
|
||||
<div class="operation">
|
||||
<button style="background: #1989fa;" onclick="saveSetting()">保存</button>
|
||||
<button style="background: #fff; color: #333">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,28 +0,0 @@
|
||||
package chaoran.business.activity;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-04 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.R;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
TextView textView = findViewById(R.id.about_content);
|
||||
textView.setText(R.string.activity_about_content);
|
||||
}
|
||||
}
|
||||
@ -15,12 +15,15 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.BrandEnum;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.adapter.*;
|
||||
import chaoran.business.vioce.TekVoiceEngine;
|
||||
import chaoran.business.vioce.VoiceEngine;
|
||||
import chaoran.business.engine.NetworkSettingEngine;
|
||||
import chaoran.business.engine.SettingEngine;
|
||||
import chaoran.business.engine.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
|
||||
/**
|
||||
* 流程:联网认证设备型号,验证通过,查找设备品牌进行调用驱动操作
|
||||
@ -34,7 +37,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
private WebView webView;
|
||||
private Adapter adapter;
|
||||
private VoiceEngine voiceEngine;
|
||||
private SettingEngine settingEngine;
|
||||
private ProgressBar progressBar;
|
||||
private ActionBar actionBar;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -68,16 +74,22 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
actionBar = getSupportActionBar();
|
||||
voiceEngine = new TekVoiceEngine(this);
|
||||
settingEngine = new NetworkSettingEngine(this);
|
||||
webView = findViewById(R.id.webView);
|
||||
progressBar = findViewById(R.id.loading);
|
||||
webView.setWebViewClient(disposeView());
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
//设置接口进行windows暴露
|
||||
settings.setDomStorageEnabled(true);
|
||||
webView.addJavascriptInterface(voiceEngine, "VoiceEngine");
|
||||
//语音引擎
|
||||
webView.addJavascriptInterface(voiceEngine, "TekVoiceEngine");
|
||||
//网络设置展示
|
||||
webView.addJavascriptInterface(settingEngine, "NetworkSettingEngine");
|
||||
//重新加载页面
|
||||
webView.addJavascriptInterface(this, "View");
|
||||
webView.loadUrl(url());
|
||||
}
|
||||
|
||||
@ -94,6 +106,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
//页面加载完成时
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
if (!url.startsWith("file"))
|
||||
actionBar.hide();
|
||||
else
|
||||
actionBar.show();
|
||||
super.onPageFinished(view, url);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -111,6 +127,8 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
default:
|
||||
webView.loadUrl("file:///android_asset/error/index.html");
|
||||
}
|
||||
actionBar.show();
|
||||
actionBar.setTitle(R.string.title_activity_main);
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -130,6 +148,8 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
webView.loadUrl("file:///android_asset/error/index.html");
|
||||
}
|
||||
}
|
||||
actionBar.show();
|
||||
actionBar.setTitle(R.string.title_activity_main);
|
||||
super.onReceivedError(view, request, error);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -172,13 +192,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
case R.id.action_setting_voice:
|
||||
startActivity(new Intent(this, VoiceSettingActivity.class));
|
||||
break;
|
||||
case R.id.action_about:
|
||||
startActivity(new Intent(this, AboutActivity.class));
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//拼接url
|
||||
private String url() {
|
||||
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
Integer port = spf.getInt("port", -1);
|
||||
@ -191,4 +209,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
return link.startsWith("http://") ? link : "http://".concat(link);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void reload() {
|
||||
runOnUiThread(() -> {
|
||||
webView.loadUrl(url());
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -31,8 +31,7 @@ public class NetworkSettingActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
setTitle(R.string.title_activity_setting_network);
|
||||
address = findViewById(R.id.address);
|
||||
path = findViewById(R.id.path);
|
||||
port = findViewById(R.id.port);
|
||||
|
||||
@ -8,14 +8,13 @@ package chaoran.business.activity;
|
||||
*/
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.widget.*;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.vioce.TekVoiceEngine;
|
||||
import chaoran.business.vioce.VoiceEngine;
|
||||
import chaoran.business.engine.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
|
||||
/**
|
||||
* 播报语音设置
|
||||
@ -41,8 +40,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
setTitle(R.string.title_activity_setting_voice);
|
||||
testText = findViewById(R.id.voice_test_text);
|
||||
voiceF = findViewById(R.id.voice_member_xiaofeng);
|
||||
voiceY = findViewById(R.id.voice_member_xiaoyan);
|
||||
@ -69,9 +67,9 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
voiceF.setChecked(false);
|
||||
}
|
||||
//设置功能选项
|
||||
voiceSize.setProgress(sharedPreferences.getInt("voiceSize", 100));
|
||||
voiceSpeed.setProgress(sharedPreferences.getInt("voiceSpeed", 80));
|
||||
voiceIndicate.setProgress(sharedPreferences.getInt("voiceIndicate", 50));
|
||||
voiceSize.setProgress(Integer.parseInt(sharedPreferences.getString("voiceSize", "100")));
|
||||
voiceSpeed.setProgress(Integer.parseInt(sharedPreferences.getString("voiceSpeed", "80")));
|
||||
voiceIndicate.setProgress(Integer.parseInt(sharedPreferences.getString("voiceIndicate", "50")));
|
||||
}
|
||||
|
||||
public void initListener() {
|
||||
@ -90,7 +88,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
//播放语音
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
}
|
||||
};
|
||||
@ -99,9 +97,9 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
voiceSpeed.setOnSeekBarChangeListener(seekBarChangeListener);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
save.setOnClickListener(a -> {
|
||||
editor.putInt("voiceSize", voiceSize.getProgress());
|
||||
editor.putInt("voiceIndicate", voiceIndicate.getProgress());
|
||||
editor.putInt("voiceSpeed", voiceSpeed.getProgress());
|
||||
editor.putString("voiceSize", String.valueOf(voiceSize.getProgress()));
|
||||
editor.putString("voiceIndicate", String.valueOf(voiceIndicate.getProgress()));
|
||||
editor.putString("voiceSpeed", String.valueOf(voiceSpeed.getProgress()));
|
||||
editor.putString("testText", testText.getText().toString());
|
||||
editor.putString("voiceMember", voiceF.isChecked() ? "xiaofeng" : "xiaoyan");
|
||||
editor.commit();
|
||||
@ -118,7 +116,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
|
||||
voiceMemberGroup.setOnCheckedChangeListener((a, b) -> {
|
||||
//播放语音
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
});
|
||||
}
|
||||
@ -127,7 +125,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
//初始化加载一次
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package chaoran.business.engine;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-18 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import chaoran.business.engine.entity.Network;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* 网络设置引擎
|
||||
*/
|
||||
public class NetworkSettingEngine implements SettingEngine {
|
||||
|
||||
private Context context;
|
||||
private Gson gson;
|
||||
|
||||
public NetworkSettingEngine(Context context) {
|
||||
gson = new Gson();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
//展示网络设置
|
||||
@Override
|
||||
@JavascriptInterface
|
||||
public String display() {
|
||||
SharedPreferences spf = context.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
Integer port = spf.getInt("port", -1);
|
||||
String address = spf.getString("address", "").replaceAll(" ", "");
|
||||
String path = spf.getString("path", "").replaceAll(" ", "");
|
||||
Network network = new Network();
|
||||
network.setAddress(address);
|
||||
network.setPort(port);
|
||||
network.setPath(path);
|
||||
return gson.toJson(network);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JavascriptInterface
|
||||
public boolean save(String s) {
|
||||
Network network = gson.fromJson(s, Network.class);
|
||||
SharedPreferences.Editor editor = context.getSharedPreferences("crtech", Context.MODE_PRIVATE).edit();
|
||||
editor.putString("address", network.getAddress());
|
||||
editor.putString("path", network.getPath());
|
||||
editor.putInt("port", network.getPort());
|
||||
editor.commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
22
app/src/main/java/chaoran/business/engine/SettingEngine.java
Normal file
22
app/src/main/java/chaoran/business/engine/SettingEngine.java
Normal file
@ -0,0 +1,22 @@
|
||||
package chaoran.business.engine;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-18 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 设置引擎
|
||||
*/
|
||||
public interface SettingEngine {
|
||||
|
||||
//显示设置
|
||||
public String display();
|
||||
|
||||
//保存设置
|
||||
public boolean save(String s);
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package chaoran.business.vioce;
|
||||
package chaoran.business.engine;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@ -8,6 +8,8 @@ import android.util.Log;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.widget.Toast;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.engine.entity.Voice;
|
||||
import com.google.gson.Gson;
|
||||
import com.iflytek.cloud.*;
|
||||
import com.iflytek.cloud.util.ResourceUtil;
|
||||
import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;
|
||||
@ -21,6 +23,9 @@ import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;
|
||||
|
||||
public class TekVoiceEngine implements VoiceEngine {
|
||||
private static String TAG = "TekVoiceEngine";
|
||||
|
||||
private Gson gson;
|
||||
|
||||
// 语音合成对象
|
||||
private SpeechSynthesizer mTts;
|
||||
|
||||
@ -35,6 +40,7 @@ public class TekVoiceEngine implements VoiceEngine {
|
||||
private Context context;
|
||||
|
||||
public TekVoiceEngine(Context context) {
|
||||
gson = new Gson();
|
||||
this.context = context;
|
||||
// 初始化合成对象
|
||||
mTts = SpeechSynthesizer.createSynthesizer(context, mTtsInitListener);
|
||||
@ -135,7 +141,9 @@ public class TekVoiceEngine implements VoiceEngine {
|
||||
};
|
||||
|
||||
|
||||
public void loadParam() {
|
||||
@Override
|
||||
@JavascriptInterface
|
||||
public String loadParam() {
|
||||
|
||||
// 装载参数之前,先清空参数
|
||||
mTts.setParameter(SpeechConstant.PARAMS, null);
|
||||
@ -153,13 +161,16 @@ public class TekVoiceEngine implements VoiceEngine {
|
||||
mTts.setParameter(SpeechConstant.VOICE_NAME, voicerLocal);
|
||||
|
||||
//设置合成语速
|
||||
mTts.setParameter(SpeechConstant.SPEED, String.valueOf(sharedPreferences.getInt("voiceSpeed", 80)));
|
||||
String voiceSpeed = sharedPreferences.getString("voiceSpeed", "80");
|
||||
mTts.setParameter(SpeechConstant.SPEED, voiceSpeed);
|
||||
|
||||
//设置合成音调
|
||||
mTts.setParameter(SpeechConstant.PITCH, String.valueOf(sharedPreferences.getInt("voiceIndicate", 50)));
|
||||
String voiceIndicate = sharedPreferences.getString("voiceIndicate", "50");
|
||||
mTts.setParameter(SpeechConstant.PITCH, voiceIndicate);
|
||||
|
||||
//设置合成音量
|
||||
mTts.setParameter(SpeechConstant.VOLUME, String.valueOf(sharedPreferences.getInt("voiceSize", 100)));
|
||||
String voiceSize = sharedPreferences.getString("voiceSize", "100");
|
||||
mTts.setParameter(SpeechConstant.VOLUME, voiceSize);
|
||||
|
||||
//设置播放器音频流类型
|
||||
mTts.setParameter(SpeechConstant.STREAM_TYPE, "3");
|
||||
@ -171,10 +182,30 @@ public class TekVoiceEngine implements VoiceEngine {
|
||||
mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
|
||||
|
||||
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/msc/tts.wav");
|
||||
|
||||
Voice voice = new Voice();
|
||||
voice.setVoiceMember(voicerLocal);
|
||||
voice.setVoiceSize(voiceSize);
|
||||
voice.setVoiceIndicate(voiceIndicate);
|
||||
voice.setVoiceSpeed(voiceSpeed);
|
||||
return gson.toJson(voice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParam(String voiceMember, Integer voiceSize, Integer voiceIndicate, Integer voiceSpeed) {
|
||||
@JavascriptInterface
|
||||
public boolean saveParam(String voiceMember, String voiceSize, String voiceIndicate, String voiceSpeed) {
|
||||
SharedPreferences.Editor editor = context.getSharedPreferences("voiceEngine", Context.MODE_PRIVATE).edit();
|
||||
editor.putString("voiceSize", voiceSize);
|
||||
editor.putString("voiceIndicate", voiceIndicate);
|
||||
editor.putString("voiceSpeed", voiceSpeed);
|
||||
editor.putString("voiceMember", voiceMember);
|
||||
editor.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JavascriptInterface
|
||||
public void setParam(String voiceMember, String voiceSize, String voiceIndicate, String voiceSpeed) {
|
||||
if (null != voiceMember) {
|
||||
//设置发音人资源路径
|
||||
mTts.setParameter(ResourceUtil.TTS_RES_PATH, getResourcePath(voiceMember));
|
||||
@ -183,15 +214,15 @@ public class TekVoiceEngine implements VoiceEngine {
|
||||
}
|
||||
if (null != voiceSize) {
|
||||
//设置合成音量
|
||||
mTts.setParameter(SpeechConstant.VOLUME, String.valueOf(voiceSize));
|
||||
mTts.setParameter(SpeechConstant.VOLUME, voiceSize);
|
||||
}
|
||||
if (null != voiceIndicate) {
|
||||
//设置合成音调
|
||||
mTts.setParameter(SpeechConstant.PITCH, String.valueOf(voiceIndicate));
|
||||
mTts.setParameter(SpeechConstant.PITCH, voiceIndicate);
|
||||
}
|
||||
if (null != voiceSpeed) {
|
||||
//设置合成语速
|
||||
mTts.setParameter(SpeechConstant.SPEED, String.valueOf(voiceSpeed));
|
||||
mTts.setParameter(SpeechConstant.SPEED, voiceSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package chaoran.business.vioce;
|
||||
package chaoran.business.engine;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
@ -20,8 +20,11 @@ public interface VoiceEngine {
|
||||
public void destroy();
|
||||
|
||||
//装载参数,从配置文件中装载参数
|
||||
public void loadParam();
|
||||
public String loadParam();
|
||||
|
||||
//保存参数,保存参数到配置文件中
|
||||
public boolean saveParam(String voiceMember, String voiceSize, String voiceIndicate, String voiceSpeed);
|
||||
|
||||
//设置参数
|
||||
public void setParam(String voiceMember, Integer voiceSize, Integer voiceIndicate, Integer voiceSpeed);
|
||||
public void setParam(String voiceMember, String voiceSize, String voiceIndicate, String voiceSpeed);
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package chaoran.business.engine.entity;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-18 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
public class Network {
|
||||
private String address;
|
||||
private Integer port;
|
||||
private String path;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
47
app/src/main/java/chaoran/business/engine/entity/Voice.java
Normal file
47
app/src/main/java/chaoran/business/engine/entity/Voice.java
Normal file
@ -0,0 +1,47 @@
|
||||
package chaoran.business.engine.entity;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-18 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
public class Voice {
|
||||
private String voiceMember;
|
||||
private String voiceSize;
|
||||
private String voiceIndicate;
|
||||
private String voiceSpeed;
|
||||
|
||||
public String getVoiceMember() {
|
||||
return voiceMember;
|
||||
}
|
||||
|
||||
public void setVoiceMember(String voiceMember) {
|
||||
this.voiceMember = voiceMember;
|
||||
}
|
||||
|
||||
public String getVoiceSize() {
|
||||
return voiceSize;
|
||||
}
|
||||
|
||||
public void setVoiceSize(String voiceSize) {
|
||||
this.voiceSize = voiceSize;
|
||||
}
|
||||
|
||||
public String getVoiceIndicate() {
|
||||
return voiceIndicate;
|
||||
}
|
||||
|
||||
public void setVoiceIndicate(String voiceIndicate) {
|
||||
this.voiceIndicate = voiceIndicate;
|
||||
}
|
||||
|
||||
public String getVoiceSpeed() {
|
||||
return voiceSpeed;
|
||||
}
|
||||
|
||||
public void setVoiceSpeed(String voiceSpeed) {
|
||||
this.voiceSpeed = voiceSpeed;
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/about_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="chaoran.business.pda.chaoran.business.activity.MainActivity">
|
||||
tools:context="chaoran.business.activity.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_setting_network"
|
||||
android:title="@string/action_setting_network"
|
||||
@ -14,9 +14,4 @@
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_about"
|
||||
android:title="@string/activity_about"
|
||||
android:orderInCategory="200"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
@ -5,8 +5,6 @@
|
||||
<string name="action_setting_voice">语音设置</string>
|
||||
<string name="title_activity_setting_voice">语音设置界面</string>
|
||||
<string name="title_activity_main">主页</string>
|
||||
<string name="activity_about">关于</string>
|
||||
<string name="activity_about_content">这是关于界面的内容</string>
|
||||
|
||||
<!-- 讯飞离线语音appid-->
|
||||
<string name="app_id">601c9ec6</string>
|
||||
|
||||
Reference in New Issue
Block a user