Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE

Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE - Welcome to ANDROID KAWE, Ini adalah sebuah blog directory tentang burung,baik itu suara burung ataupun tips perawatan burung.Blog ini adalah situs perangkum otomatis dari pencarian google yang kali ini berjudul Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE.Ada ribuan artikel yang sudah terekam ke dalam situs ini,silahkan cari sesuai yang kalian kehendaki,untuk artikel selanjutnya tentang judul diatas bisa kalian baca di bawah ini.

Konten : Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE
Judul : Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE

lihat juga


Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE

Android Text to speech Example

Hi Friend
  Today we explain how to create Android Narrator.
Android provide text to speech class. using this class we can easily create an message reader type application, using the method of this class we can control speed of narrating and sound pitch also.

Java source Code for Narrator:


package in.androidshivendra.texttospeechexample;


import java.util.Locale;

import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Spinner;

public class MainActivity extends Activity implements
TextToSpeech.OnInitListener{
   String speed[] = {  "Very Slow", "Slow", "Normal", "Fast", "Very Fast"};
   Float speedf[] = {(float) 0.1,(float) 0.5,(float) 1.0,(float) 1.5,(float) 2.0};
   Spinner spspeed;
   Button btn;
   EditText emsg;
   RadioGroup rg;
   TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter adp = new ArrayAdapter(MainActivity.this, android.R.layout.simple_spinner_item,speed);
 
spspeed = (Spinner)findViewById(R.id.spinner1);
btn = (Button)findViewById(R.id.button1);
emsg = (EditText)findViewById(R.id.editText1);
rg = (RadioGroup)findViewById(R.id.radioGroup1);
tts = new TextToSpeech(this,this);
spspeed.setAdapter(adp);
spspeed.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
tts.setSpeechRate(speedf[arg2]);
}

@Override
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
tts.setSpeechRate((float)1.0);
}
});
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
RadioButton rb = (RadioButton)findViewById(checkedId);
if(rb.isChecked())
{
String gen = rb.getText().toString();
if(gen.equals("Male"))
tts.setPitch(1.0f);
else
tts.setPitch(2.5f);
}
}
});
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String text = emsg.getText().toString();
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {

   int result = tts.setLanguage(Locale.ENGLISH);

   if (result == TextToSpeech.LANG_MISSING_DATA
           || result == TextToSpeech.LANG_NOT_SUPPORTED) {
       Log.e("TTS", "This Language is not supported");
   } else {
    btn.setEnabled(true);
   
   }

} else {
   Log.e("TTS", "Initilization Failed!");
}
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
   tts.stop();
   tts.shutdown();
}
super.onDestroy();
}

}

Layout xml code:-



    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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" >

   
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textMultiLine" >

       
   

   



You can download Text- to - speech- example here




Demikianlah Artikel Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE

Semoga artikel tentang Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE, mudah-mudahan bisa memberi manfaat untuk anda semua.

Anda sedang membaca artikel Android Tutorial-Android-Text-to-Speech-exampleANDROIDKAWE dan artikel ini url permalinknya adalah http://androidkawe.blogspot.com/2016/12/android-tutorial-android-text-to-speech.html Semoga artikel ini bisa bermanfaat.Sekali lagi,ini adalah situs auto yang tidak ditulis langsung oleh admin,Kami tidak menjamin akan kebenaran dari artikel yang tertulis.
Back To Top