Skip to content

Commit

Permalink
Init project
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan12352 committed Jun 16, 2019
1 parent 21a6622 commit 4880bff
Show file tree
Hide file tree
Showing 109 changed files with 8,823 additions and 0 deletions.
9 changes: 9 additions & 0 deletions JapaneseTTS/.gitignore
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
22 changes: 22 additions & 0 deletions JapaneseTTS/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions JapaneseTTS/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions JapaneseTTS/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions JapaneseTTS/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions JapaneseTTS/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions JapaneseTTS/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JapaneseTTS/TTSLibrary/.gitignore
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions JapaneseTTS/TTSLibrary/build.gradle
@@ -0,0 +1,26 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26



defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
}
21 changes: 21 additions & 0 deletions JapaneseTTS/TTSLibrary/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions JapaneseTTS/TTSLibrary/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.java.ttslibrary" />
182 changes: 182 additions & 0 deletions JapaneseTTS/TTSLibrary/src/main/java/com/java/ttslibrary/TTSLib.java
@@ -0,0 +1,182 @@
package com.java.ttslibrary;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;

import java.util.HashMap;
import java.util.Locale;
import java.util.Set;

import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.media.AudioManager;
import java.util.Locale;

public class TTSLib {
static TextToSpeech tts;
static Locale _locale = Locale.JAPANESE;
static String packagetouse = "com.google.android.tts";

static Bundle bundle = null;
static HashMap<String, String> param;
static Locale.Builder builder = new Locale.Builder();

public static boolean IsRunning(){
return (tts!=null);
}

public static void SetPitch(float pitch){
if(tts!=null){
tts.setPitch(pitch);
}
}

public static void SetSpeedRate(float speechrate){
if(tts!=null){
tts.setSpeechRate(speechrate);
}
}

public static boolean SetLocale(String locale, String script, String region){
Locale locale_ = builder.setLanguage(locale).setScript(script).setRegion(region).build();
if(tts==null){
return false;
}
int result = tts.setLanguage(locale_);
if (result == TextToSpeech.LANG_MISSING_DATA|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
return false;
}
_locale = locale_;
return true;
}

public static String GetLocale(){
return (tts!=null) ? tts.getLanguage().toString() : "";
}

public static String[] GetAvailableLocales(){

/*if(instance.tts!=null){
Set<Locale> locales = instance.tts.getAvailableLanguages();
String[] temp = new String[locales.size()];
Locale[] _locales = locales.toArray(new Locale[0]);
for(int i=0;i<locales.size();i++){
temp[i]=_locales[i].toString();
}
return temp;
}
return new String[]{};*/
Locale[] locales = Locale.getAvailableLocales();
String[] temp = new String[locales.length];

for(int i=0;i<locales.length;i++){
temp[i] = locales[i].toString();
}

return temp;
}

public static boolean setEngineByPackageName(String packagename){

if(tts!=null && tts.setEngineByPackageName(packagename)==TextToSpeech.SUCCESS){
return true;
}
return false;
}


public static void StartTTS(final Activity activity)
{
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);

tts = new TextToSpeech(activity.getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {

int result = tts.setLanguage(Locale.JAPANESE);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("error", "Language Not supported");
DownloadTTSData(activity);
}
else{
Log.v("TTS","onInit succeeded");
}
} else {
Log.e("error","Initialization Failed");
}

}
},packagetouse);
}

public static void DownloadTTSData(Activity activity) {
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
activity.startActivity(installTTSIntent);
}

public static boolean IsUttering() {
if(tts!=null && tts.isSpeaking()){
return true;
}
return false;
}

public static void StopUtterance(){
if(tts!=null){
tts.stop();
}
}

public static boolean GetLanguageAvailability(Activity activity, String locale) {
int result = tts.isLanguageAvailable(builder.setLanguage(locale).build());

if(!(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)) {
return true;
}
else {
//DownloadTTSData(activity);
return false;
}
}

public static void Speak(String s){

//Log.e("error","SpeakJapanese Is Running normally: " + tts.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//Log.v("Change to new API", "Speak new API");
if(bundle==null){
Bundle bundle = new Bundle();
bundle.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_MUSIC);
}
tts.speak(s, TextToSpeech.QUEUE_FLUSH, bundle, null);
} else {
//Log.v(s, "Speak old API");
if(param==null){
param = new HashMap<>();
param.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
}

tts.speak(s, TextToSpeech.QUEUE_FLUSH, param);
}
}

static protected void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
Log.v("onDestroy()","onDestroy: shutdown TTS");
tts.stop();
tts.shutdown();
}
}

public static void StopTTS() {
onDestroy();
}
}
3 changes: 3 additions & 0 deletions JapaneseTTS/TTSLibrary/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">TTSLibrary</string>
</resources>
1 change: 1 addition & 0 deletions JapaneseTTS/app/.gitignore
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions JapaneseTTS/app/build.gradle
@@ -0,0 +1,23 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.jongamedev.ttstest"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
}

0 comments on commit 4880bff

Please sign in to comment.