All About Android-Using Speech Engine in Android-ANDROIDKAWE - 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 All About Android-Using Speech Engine in Android-ANDROIDKAWE.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 : All About Android-Using Speech Engine in Android-ANDROIDKAWE
Judul : All About Android-Using Speech Engine in Android-ANDROIDKAWE
This post is focusing on speech engine in Android SDK. The TTS engine is very important component of the Android SDK and the Android 4.0 version has great APIs to write the custom TTS engines.
Here i am explaining a sample code to use the TTS engine in your android application.
Create the following layout in your android application.
Here is the code of the sample speak activity you can just copy and paste this in your application project.
If you like the code please share your feedback.
Thanks
Anda sedang membaca artikel All About Android-Using Speech Engine in Android-ANDROIDKAWE dan artikel ini url permalinknya adalah http://androidkawe.blogspot.com/2016/03/all-about-android-using-speech-engine.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.
Konten : All About Android-Using Speech Engine in Android-ANDROIDKAWE
Judul : All About Android-Using Speech Engine in Android-ANDROIDKAWE
All About Android-Using Speech Engine in Android-ANDROIDKAWE
This post is focusing on speech engine in Android SDK. The TTS engine is very important component of the Android SDK and the Android 4.0 version has great APIs to write the custom TTS engines.
Here i am explaining a sample code to use the TTS engine in your android application.
Create the following layout in your android application.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" >
<TextView android:id="@+id/msglabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter some text in english:"
/>
<EditText android:id="@+id/inputtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/speakenglish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="speak in english"
/>
</LinearLayout>
Here is the code of the sample speak activity you can just copy and paste this in your application project.
package com.example.speaksample;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.view.View;
import android.widget.EditText;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.content.Intent;
import java.util.Locale;
import android.widget.Toast;
public class speaksample extends Activity implements OnClickListener, OnInitListener {
//Create the TTS object
private TextToSpeech TTSObject;
//status check code
private int DATA_CHECK_CODE = 0;
//create the Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speaking_android);
//get a reference to the button element listed in the XML layout
Button speakButton = (Button)findViewById(R.id.speakenglish);
//set the click listener
speakButton.setOnClickListener(this);
//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, DATA_CHECK_CODE);
}
//respond to button clicks
public void onClick(View v) {
//get the text entered
EditText inputtext = (EditText)findViewById(R.id.inputtext);
String data = inputtext.getText().toString();
speakInEnglish(data);
}
//speak the user text
private void speakInEnglish(String speech) {
//speak straight away
TTSObject.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
//act on result of TTS data check
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
//the user has the necessary data - create the TTS
TTSObject = new TextToSpeech(this, this);
}
else {
//no data - install it now
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
}
//setup TTS
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) {
if(TTSObject.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
TTSObject.setLanguage(Locale.US);
}
else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(this, "TTS engine fails", Toast.LENGTH_LONG).show();
}
}
}
If you like the code please share your feedback.
Thanks
Demikianlah Artikel All About Android-Using Speech Engine in Android-ANDROIDKAWE
Semoga artikel tentang All About Android-Using Speech Engine in Android-ANDROIDKAWE, mudah-mudahan bisa memberi manfaat untuk anda semua.
Anda sedang membaca artikel All About Android-Using Speech Engine in Android-ANDROIDKAWE dan artikel ini url permalinknya adalah http://androidkawe.blogspot.com/2016/03/all-about-android-using-speech-engine.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.