0% found this document useful (0 votes)
33 views5 pages

Desarrollo de Aplicación Text To Speech Android Studio.: Facultad de Ingeniería en Ciencias de La Computación

This document is a report for a text-to-speech Android application project. It includes an introduction, screenshot of the application, and code for the MainActivity and Speech classes. The MainActivity class controls the user interface and calls the Speech class to initialize text-to-speech. The Speech class initializes the text-to-speech engine, sets the Spanish language, and provides methods to add text to the queue and speak it aloud. The project was completed by two students for a mobile development class taught in February 2021.

Uploaded by

René Carrillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Desarrollo de Aplicación Text To Speech Android Studio.: Facultad de Ingeniería en Ciencias de La Computación

This document is a report for a text-to-speech Android application project. It includes an introduction, screenshot of the application, and code for the MainActivity and Speech classes. The MainActivity class controls the user interface and calls the Speech class to initialize text-to-speech. The Speech class initializes the text-to-speech engine, sets the Spanish language, and provides methods to add text to the queue and speak it aloud. The project was completed by two students for a mobile development class taught in February 2021.

Uploaded by

René Carrillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Facultad de ingeniería en Ciencias de la computación.

Desarrollo de Aplicación Text To Speech


Android Studio.

GT:
02T

Docente:
Alex Jiménez

Integrantes:

Carrillo Garcia Rene Alexander CG152751


Hernández López Manuel Oswaldo HL180507

Fecha de entrega:

Sábado 17 de febrero del 2021

Introducción
Captura de Aplicación en Ejecución
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

private Button repoducir;


private EditText editText;
Speech speech= null;

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

speech=new Speech();
speech.init(this);

editText=findViewById(R.id.eTT);
repoducir=findViewById(R.id.btnReproducir);

repoducir.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String text=editText.getText().toString();
speech.initQueue(text);
}
});
}

protected void onDestroy(){


super.onDestroy();
speech.shutDown();
}

Speech.java
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;

import java.util.Locale;

public class Speech {

private TextToSpeech tts;


private boolean isLoaded = false;

public void init(Context context) {


try {
tts = new TextToSpeech(context, onInitListener);
} catch (Exception e) {
e.printStackTrace();
}
}

private TextToSpeech.OnInitListener onInitListener = new TextToSpeech.OnInitListener() {


@Override
public void onInit(int status) {
Locale spanish = new Locale("es", "ES");
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(spanish);
isLoaded = true;

if (result == TextToSpeech.LANG_MISSING_DATA || result ==


TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("error", "Este Lenguaje no esta permitido");
} else {
Log.e("error", "Falla al Inicializar");
}
}
}

};

public void shutDown() {

tts.shutdown();
}

public void addQueue(String text) {


if(isLoaded)
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
else
Log.e("error", "TTS Not Initialized");
}
void initQueue(String text){
if(isLoaded)
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
else
Log.e("error", "TSS Not Initialized");
}

You might also like