Texto a voz (TTS) -Android
Soy nuevo en la plataforma android. Ahora estoy trabajando en TTS(Text to Speech)
.Si introdujo el texto en un TextArea y me gustaría que se convierten a voz cuando hago clic en el botón de hablar.
¿Puede alguien ayudarme?
- Hablar con TTS como Hindi
- Pausa tono del teléfono mientras habla a través de texto a voz y luego reanudar
- ¿Cómo puedo guardar la salida TTS en un archivo de audio en android?
- ¿Cómo puedo guardar el archivo Text to Speech como formato .wav / .mp3 en idioma árabe en External Storage?
- Obtener locales disponibles para tts
- Ampliación del paquete de idiomas de texto a voz (TTS) de Android
- Sistema lengua turca para el texto al discurso
- ¿Cómo agregar voces nuevas a Android Pico TTS?
- Idiomas faltantes en TTS android
- Cómo encuestar los motores TTS disponibles para los idiomas disponibles sin instanciar cada uno y wating para init
- ¿Cómo puedo guardar el archivo Text to Speech como formato .wav / .mp3 en Almacenamiento externo
- Android TTS Masculino Masculino Voz Cambio
- Transmisión de notificaciones de texto a voz durante la conducción
Texto a voz está integrado en Android 1.6+. Aquí hay un ejemplo sencillo de cómo hacerlo.
TextToSpeech tts = new TextToSpeech(this, this); tts.setLanguage(Locale.US); tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
Más información: http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
Aquí hay instrucciones sobre cómo descargar código de ejemplo del Administrador de SDK de Android:
-
Inicie el Administrador de SDK de Android.
a. En Windows, haga doble clic en el archivo SDK Manager.exe en la raíz del directorio SDK de Android.
segundo. En Mac o Linux, abra un terminal al directorio tools / en el SDK de Android, luego ejecute android sdk.
-
Amplíe la lista de paquetes de la última plataforma de Android.
- Seleccione y descargue Muestras para SDK. Cuando se completa la descarga, puede encontrar el código fuente de todas las muestras en esta ubicación:
/ Sdk / samples / android-version /
(ie \android-sdk-windows\samples\android-16\ApiDemos\src\com\example\android\apis\app\TextToSpeechActivity.java)
package com.example.texttospeech; import java.util.Locale; import android.os.Bundle; import android.app.Activity; import android.content.SharedPreferences.Editor; import android.speech.tts.TextToSpeech; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { String text; EditText et; TextToSpeech tts; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et=(EditText)findViewById(R.id.editText1); tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { // TODO Auto-generated method stub if(status == TextToSpeech.SUCCESS){ int result=tts.setLanguage(Locale.US); if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED){ Log.e("error", "This Language is not supported"); } else{ ConvertTextToSpeech(); } } else Log.e("error", "Initilization Failed!"); } }); } @Override protected void onPause() { // TODO Auto-generated method stub if(tts != null){ tts.stop(); tts.shutdown(); } super.onPause(); } public void onClick(View v){ ConvertTextToSpeech(); } private void ConvertTextToSpeech() { // TODO Auto-generated method stub text = et.getText().toString(); if(text==null||"".equals(text)) { text = "Content not available"; tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); }else tts.speak(text+"is saved", TextToSpeech.QUEUE_FLUSH, null); } } <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="177dp" android:onClick="onClick" android:text="Button" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:layout_centerHorizontal="true" android:layout_marginBottom="81dp" android:ems="10" > <requestFocus /> </EditText> </RelativeLayout>
Prueba esto, es simple: ** speakout.xml: **
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#3498db" android:weightSum="1" android:orientation="vertical" > <TextView android:id="@+id/txtheader" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight=".1" android:gravity="center" android:padding="3dp" android:text="Speak Out!!!" android:textColor="#fff" android:textSize="25sp" android:textStyle="bold" /> <EditText android:id="@+id/edtTexttoSpeak" android:layout_width="match_parent" android:layout_weight=".5" android:background="#fff" android:textColor="#2c3e50" android:text="Hi there!!!" android:padding="5dp" android:gravity="top|left" android:layout_height="0dp"/> <Button android:id="@+id/btnspeakout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".1" android:background="#e74c3c" android:textColor="#fff" android:text="SPEAK OUT"/> </LinearLayout>
Y tu SpeakOut.java:
import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; import android.view.View; import android.widget.Button; import android.widget.EditText; public class SpeakOut extends Activity implements OnInitListener { private TextToSpeech repeatTTS; Button btnspeakout; EditText edtTexttoSpeak; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.speakout); btnspeakout = (Button) findViewById(R.id.btnspeakout); edtTexttoSpeak = (EditText) findViewById(R.id.edtTexttoSpeak); repeatTTS = new TextToSpeech(this, this); btnspeakout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { repeatTTS.speak(edtTexttoSpeak.getText().toString(), TextToSpeech.QUEUE_FLUSH, null); } }); } @Override public void onInit(int arg0) { // TODO Auto-generated method stub } }
FUENTE Parallelcodes.com's Post
public class Texttovoice extends ActionBarActivity implements OnInitListener { private TextToSpeech tts; private Button btnSpeak; private EditText txtText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_texttovoice); tts = new TextToSpeech(this, this); // Refer 'Speak' button btnSpeak = (Button) findViewById(R.id.btnSpeak); // Refer 'Text' control txtText = (EditText) findViewById(R.id.txtText); // Handle onClick event for button 'Speak' btnSpeak.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // Method yet to be defined speakOut(); } }); } private void speakOut() { // Get the text typed String text = txtText.getText().toString(); // If no text is typed, tts will read out 'You haven't typed text' // else it reads out the text you typed if (text.length() == 0) { tts.speak("You haven't typed text", TextToSpeech.QUEUE_FLUSH, null); } else { tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } } public void onDestroy() { // Don't forget to shutdown! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.texttovoice, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public void onInit(int status) { // TODO Auto-generated method stub // TTS is successfully initialized if (status == TextToSpeech.SUCCESS) { // Setting speech language int result = tts.setLanguage(Locale.US); // If your device doesn't support language you set above if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { // Cook simple toast message with message Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_LONG).show(); Log.e("TTS", "Language is not supported"); } // Enable the button - It was disabled in main.xml (Go back and // Check it) else { btnSpeak.setEnabled(true); } // TTS is not initialized properly } else { Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG) .show(); Log.e("TTS", "Initilization Failed"); } } //-------------------------------XML--------------- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:orientation="vertical" tools:ignore="HardcodedText" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="15dip" android:text="listen your text" android:textColor="#0587d9" android:textSize="26dip" android:textStyle="bold" /> <EditText android:id="@+id/txtText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dip" android:layout_marginTop="20dip" android:hint="Enter text to speak" /> <Button android:id="@+id/btnSpeak" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dip" android:enabled="false" android:text="Speak" android:onClick="speakout"/>
- Infowindow personalizado en el mapa de Google android v2
- Lanzamiento de actividades dentro de una pestaña en Android