Skip to content

Commit

Permalink
Customize Text-To-Speech
Browse files Browse the repository at this point in the history
  • Loading branch information
Jevin-Studios committed Feb 14, 2018
1 parent 013949e commit d46a9bf
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 12 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
4 changes: 4 additions & 0 deletions app/src/main/java/com/jeffg/livetextview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.jeffg.live_text_view.LiveTextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
}
12 changes: 4 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.jeffg.live_text_view.LiveTextView
android:id="@+id/liveTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "https://dl.bintray.com/jeffg05/Live-Text-View"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion live-text-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
siteUrl = 'https://github.com/JeffG05/LiveTextView'
gitUrl = 'https://github.com/JeffG05/LiveTextView.git'

libraryVersion = "1.0.2"
libraryVersion = "1.0.3"

developerId = "jeffg05"
developerName = "Jeff Gugelmann"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Color;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.speech.tts.Voice;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class LiveTextView extends RelativeLayout {
boolean animate;
boolean paused;
boolean playing;
LiveTextViewTTS liveTextViewTTS;

ArrayList<String> text;
TextToSpeech textToSpeech;
Expand Down Expand Up @@ -113,6 +115,10 @@ public void animate(boolean bool) {
animate = bool;
}

public void setLiveTextViewTTS(LiveTextViewTTS tts) {
liveTextViewTTS = tts;
}

public void setSmallTextSize(int size) {
previous.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
next.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
Expand Down Expand Up @@ -364,6 +370,21 @@ public void start() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
if(liveTextViewTTS.pitch != null) {
textToSpeech.setPitch(liveTextViewTTS.pitch);
}
if(liveTextViewTTS.language != null) {
textToSpeech.setLanguage(liveTextViewTTS.language);
}
if(liveTextViewTTS.audioAttributes != null) {
textToSpeech.setAudioAttributes(liveTextViewTTS.audioAttributes);
}
if(liveTextViewTTS.speechRate != null) {
textToSpeech.setSpeechRate(liveTextViewTTS.speechRate);
}
if(liveTextViewTTS.voice != null) {
textToSpeech.setVoice(liveTextViewTTS.voice);
}
textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String s) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.jeffg.live_text_view;

import android.media.AudioAttributes;
import android.speech.tts.TextToSpeech;
import android.speech.tts.Voice;

import java.util.Locale;

public class LiveTextViewTTS {

Float pitch;
Locale language;
Float speechRate;
Voice voice;
AudioAttributes audioAttributes;

public LiveTextViewTTS() {

}

public LiveTextViewTTS setBuilder(Builder builder) {
this.pitch = builder.pitch;
this.language = builder.language;
this.speechRate = builder.speechRate;
this.voice = builder.voice;
this.audioAttributes = builder.audioAttributes;
return this;
}



class Builder {
Float pitch;
Locale language;
Float speechRate;
Voice voice;
AudioAttributes audioAttributes;

public Builder setPitch(float pitch) {
this.pitch = pitch;
return this;
}

public Builder setLanguage(Locale language) {
this.language = language;
return this;
}

public Builder setSpeechRate(float speechRate) {
this.speechRate = speechRate;
return this;
}

public Builder setVoice(Voice voice) {
this.voice = voice;
return this;
}

public Builder setAudioAttributes(AudioAttributes audioAttributes) {
this.audioAttributes = audioAttributes;
return this;
}

public LiveTextViewTTS build() {
return new LiveTextViewTTS().setBuilder(this);
}

}

}

0 comments on commit d46a9bf

Please sign in to comment.