提交 019927e6 编写于 作者: T Takeya Yuki

Add TTS Functions

上级 3cb995aa
...@@ -7,6 +7,7 @@ Network Detect<br/> ...@@ -7,6 +7,7 @@ Network Detect<br/>
Storage IO<br/> Storage IO<br/>
Command Line Support<br/> Command Line Support<br/>
UI Control Features (Status Bar and Navigation Bar)<br/> UI Control Features (Status Bar and Navigation Bar)<br/>
TTS Features<br/>
## Current Version ## Current Version
1.0-git-201706291123 1.0-git-201708111646
package jp.ruby.rubylibrary;
/**
* Created by Akeno on 2017/06/30.
*/
public class A {
public int a;
public String b;
}
package jp.ruby.rubylibrary;
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import java.util.Locale;
/**
* Created by Akeno on 2017/08/11.
*/
public class JS {
private Context context;
private TextToSpeech tts;
public JS(final Context context) {
// TODO Auto-generated constructor stub
this.context = context;
tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.SIMPLIFIED_CHINESE);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(context, "Language is not available.", Toast.LENGTH_SHORT).show();
}
}
}
});
}
@JavascriptInterface
public void say(String text) {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
...@@ -16,11 +16,13 @@ import android.widget.LinearLayout; ...@@ -16,11 +16,13 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Locale;
import yuki.control.extended.WebViewEx; import yuki.control.extended.WebViewEx;
import yuki.resource.extended.GsonConvert; import yuki.resource.extended.GsonConvert;
import yuki.resource.extended.StorageIOManager; import yuki.resource.extended.StorageIOManager;
import yuki.resource.extended.UIController; import yuki.resource.extended.UIController;
import yuki.tts.extended.TTSComplexController;
public class MainActivity extends Activity { public class MainActivity extends Activity {
...@@ -28,16 +30,12 @@ public class MainActivity extends Activity { ...@@ -28,16 +30,12 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
A a=new A(); WebView wv = (WebView) findViewById(R.id.wv);
a.a=1; wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
a.b="hello world!"; wv.getSettings().setJavaScriptEnabled(true);
TextView tv=findViewById(R.id.tv); wv.loadUrl("http://10.1.1.134:8282/Client.html");
String gson=GsonConvert.SerializeObject(a); wv.addJavascriptInterface(new TTSComplexController(getApplicationContext(), Locale.SIMPLIFIED_CHINESE), "tts");
tv.setText(gson); //wv.addJavascriptInterface(new JS(getApplicationContext()), "tts");
A b=GsonConvert.DeserializeObject(gson,A.class);
b=null;
Intent aa=new Intent(Intent.ACTION_VIEW, Uri.parse("weixin://baidu.com/"));
startActivity(aa);
} }
} }
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
android:orientation="vertical" android:orientation="vertical"
tools:context="jp.ruby.rubylibrary.MainActivity"> tools:context="jp.ruby.rubylibrary.MainActivity">
<TextView <WebView
android:id="@+id/tv" android:id="@+id/wv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent" />
android:text="TextView" />
</LinearLayout> </LinearLayout>
...@@ -7,7 +7,7 @@ publish { ...@@ -7,7 +7,7 @@ publish {
userOrg = 'takeya-yuki-studio' //bintray注册的用户名 userOrg = 'takeya-yuki-studio' //bintray注册的用户名
groupId = 'jp.ruby.rubylib' //compile引用时的第1部分groupId groupId = 'jp.ruby.rubylib' //compile引用时的第1部分groupId
artifactId = 'rubylib' //compile引用时的第2部分项目名 artifactId = 'rubylib' //compile引用时的第2部分项目名
publishVersion = '1.0.4' //compile引用时的第3部分版本号 publishVersion = '1.0.5' //compile引用时的第3部分版本号
desc = 'Ruby Extended Controls' desc = 'Ruby Extended Controls'
website = 'https://github.com/Takeya-Yuki/RubyLib.git' website = 'https://github.com/Takeya-Yuki/RubyLib.git'
} }
...@@ -20,8 +20,8 @@ android { ...@@ -20,8 +20,8 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 26 targetSdkVersion 26
versionCode 4 versionCode 5
versionName "1.0.4" versionName "1.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
......
package yuki.tts.extended;
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.util.Log;
import android.webkit.JavascriptInterface;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Created by Akeno on 2017/08/11.
*/
public class TTSComplexController {
private Context context;
private TextToSpeech tts;
private ArrayList<String> textList;
public TTSComplexController(final Context context,final Locale locale){
// TODO Auto-generated constructor stub
this.context = context;
textList=new ArrayList<String>();
tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(locale);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.d("TTS","Language '"+locale.getDisplayLanguage()+"'is not supported");
}
}
}
});
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String s) {
}
@Override
public void onDone(String s) {
if(textList.size()>0) {
textList.remove(0);
}
}
@Override
public void onError(String s) {
}
});
}
@JavascriptInterface
public void say(String text) {
textList.add(text);
tts.speak(text,TextToSpeech.QUEUE_ADD,null);
}
}
package yuki.tts.extended;
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import java.util.Locale;
/**
* Created by Akeno on 2017/08/11.
*/
public class TTSSimpleController {
private Context context;
private TextToSpeech tts;
public TTSSimpleController(final Context context,final Locale locale){
// TODO Auto-generated constructor stub
this.context = context;
tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(locale);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.d("TTS","Language '"+locale.getDisplayLanguage()+"'is not supported");
}
}
}
});
}
@JavascriptInterface
public void say(String text) {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册