From 019927e6da9dc6ed46783dcc4a271f7a70544266 Mon Sep 17 00:00:00 2001 From: Takeya Yuki Date: Fri, 11 Aug 2017 16:46:39 +0800 Subject: [PATCH] Add TTS Functions --- README.md | 3 +- app/src/main/java/jp/ruby/rubylibrary/A.java | 10 --- app/src/main/java/jp/ruby/rubylibrary/JS.java | 40 ++++++++++++ .../jp/ruby/rubylibrary/MainActivity.java | 18 +++--- app/src/main/res/layout/activity_main.xml | 7 +-- rubylib/build.gradle | 6 +- .../tts/extended/TTSComplexController.java | 63 +++++++++++++++++++ .../tts/extended/TTSSimpleController.java | 40 ++++++++++++ 8 files changed, 159 insertions(+), 28 deletions(-) delete mode 100644 app/src/main/java/jp/ruby/rubylibrary/A.java create mode 100644 app/src/main/java/jp/ruby/rubylibrary/JS.java create mode 100644 rubylib/src/main/java/yuki/tts/extended/TTSComplexController.java create mode 100644 rubylib/src/main/java/yuki/tts/extended/TTSSimpleController.java diff --git a/README.md b/README.md index 6624eac..36804e9 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Network Detect
Storage IO
Command Line Support
UI Control Features (Status Bar and Navigation Bar)
+TTS Features
## Current Version -1.0-git-201706291123 +1.0-git-201708111646 diff --git a/app/src/main/java/jp/ruby/rubylibrary/A.java b/app/src/main/java/jp/ruby/rubylibrary/A.java deleted file mode 100644 index 311b446..0000000 --- a/app/src/main/java/jp/ruby/rubylibrary/A.java +++ /dev/null @@ -1,10 +0,0 @@ -package jp.ruby.rubylibrary; - -/** - * Created by Akeno on 2017/06/30. - */ - -public class A { - public int a; - public String b; -} diff --git a/app/src/main/java/jp/ruby/rubylibrary/JS.java b/app/src/main/java/jp/ruby/rubylibrary/JS.java new file mode 100644 index 0000000..b65b60d --- /dev/null +++ b/app/src/main/java/jp/ruby/rubylibrary/JS.java @@ -0,0 +1,40 @@ +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); + } +} + diff --git a/app/src/main/java/jp/ruby/rubylibrary/MainActivity.java b/app/src/main/java/jp/ruby/rubylibrary/MainActivity.java index 02fd0f1..79757e2 100644 --- a/app/src/main/java/jp/ruby/rubylibrary/MainActivity.java +++ b/app/src/main/java/jp/ruby/rubylibrary/MainActivity.java @@ -16,11 +16,13 @@ import android.widget.LinearLayout; import android.widget.TextView; import java.nio.charset.Charset; +import java.util.Locale; import yuki.control.extended.WebViewEx; import yuki.resource.extended.GsonConvert; import yuki.resource.extended.StorageIOManager; import yuki.resource.extended.UIController; +import yuki.tts.extended.TTSComplexController; public class MainActivity extends Activity { @@ -28,16 +30,12 @@ public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - A a=new A(); - a.a=1; - a.b="hello world!"; - TextView tv=findViewById(R.id.tv); - String gson=GsonConvert.SerializeObject(a); - tv.setText(gson); - A b=GsonConvert.DeserializeObject(gson,A.class); - b=null; - Intent aa=new Intent(Intent.ACTION_VIEW, Uri.parse("weixin://baidu.com/")); - startActivity(aa); + WebView wv = (WebView) findViewById(R.id.wv); + wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); + wv.getSettings().setJavaScriptEnabled(true); + wv.loadUrl("http://10.1.1.134:8282/Client.html"); + wv.addJavascriptInterface(new TTSComplexController(getApplicationContext(), Locale.SIMPLIFIED_CHINESE), "tts"); + //wv.addJavascriptInterface(new JS(getApplicationContext()), "tts"); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8c68c42..151cf76 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,9 +7,8 @@ android:orientation="vertical" tools:context="jp.ruby.rubylibrary.MainActivity"> - + android:layout_height="match_parent" /> diff --git a/rubylib/build.gradle b/rubylib/build.gradle index 2d8bb62..4041c9c 100644 --- a/rubylib/build.gradle +++ b/rubylib/build.gradle @@ -7,7 +7,7 @@ publish { userOrg = 'takeya-yuki-studio' //bintray注册的用户名 groupId = 'jp.ruby.rubylib' //compile引用时的第1部分groupId artifactId = 'rubylib' //compile引用时的第2部分项目名 - publishVersion = '1.0.4' //compile引用时的第3部分版本号 + publishVersion = '1.0.5' //compile引用时的第3部分版本号 desc = 'Ruby Extended Controls' website = 'https://github.com/Takeya-Yuki/RubyLib.git' } @@ -20,8 +20,8 @@ android { defaultConfig { minSdkVersion 17 targetSdkVersion 26 - versionCode 4 - versionName "1.0.4" + versionCode 5 + versionName "1.0.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/rubylib/src/main/java/yuki/tts/extended/TTSComplexController.java b/rubylib/src/main/java/yuki/tts/extended/TTSComplexController.java new file mode 100644 index 0000000..b6b63d8 --- /dev/null +++ b/rubylib/src/main/java/yuki/tts/extended/TTSComplexController.java @@ -0,0 +1,63 @@ +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 textList; + + public TTSComplexController(final Context context,final Locale locale){ + + // TODO Auto-generated constructor stub + this.context = context; + textList=new ArrayList(); + 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); + } +} diff --git a/rubylib/src/main/java/yuki/tts/extended/TTSSimpleController.java b/rubylib/src/main/java/yuki/tts/extended/TTSSimpleController.java new file mode 100644 index 0000000..1d3b37e --- /dev/null +++ b/rubylib/src/main/java/yuki/tts/extended/TTSSimpleController.java @@ -0,0 +1,40 @@ +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); + } +} -- GitLab