-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTTS.java
38 lines (35 loc) · 1.16 KB
/
TTS.java
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
package com.example.tts;
import androidx.appcompat.app.AppCompatActivity;
import android.speech.tts.TextToSpeech;
import android.os.Bundle;
import java.util.Locale;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText ed;
Button btn;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed = findViewById(R.id.text);
btn = findViewById(R.id.btn);
textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if(i != TextToSpeech.ERROR)
{
textToSpeech.setLanguage(Locale.US);
}
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textToSpeech.speak(ed.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
});
}
}