-
Notifications
You must be signed in to change notification settings - Fork 9
/
Text to speech
60 lines (54 loc) · 1.37 KB
/
Text to speech
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.speech.RecognizerIntent;
import android.content.*;
String str = "Hi there. This is your beloved phone speaking to you.";
TextToSpeech my_tts;
Activity activity;
Context context;
void setup() {
fullScreen();
background(0, 0, 200);
fill(200);
rect(width/4, 7*height/16, width/2, height/8);
textAlign(CENTER, CENTER);
textSize(60);
fill(0);
text("SPEAK", width/2, height/2);
activity = this.getActivity();
context = activity.getApplicationContext();
}
void draw(){}
void mousePressed() {
if (mouseX < 3*width/4 && mouseX > width/4 &&
mouseY > 7*height/16 && mouseY < 9*height/16) {
try {
my_tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
println("success");
my_tts.setLanguage(Locale.UK);
my_tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
}
}
}
);
}
catch(Exception e) {
println(e);
}
}
}
public void onPause() {
if (my_tts !=null) {
my_tts.stop();
my_tts.shutdown();
}
super.onPause();
}