Android 中的文本转语音可离线使用
Text-To-Speech in Android That Works Offline
我和我的朋友正在开发一款使用深度学习和神经网络来帮助视障人士的应用程序。我们正在寻找一种方法,将神经网络通过智能手机摄像头获取的信息通过语音返回给用户,因此我们需要进行 TextToSpeech。
然而,对于用户来说,让应用程序离线工作是一个巨大的交易,因为应用程序的所有其他部分都能够运行没有互联网连接(神经网络等)我们'我们正在寻找离线进行 TextToSpeech 的方法。该应用程序也是俄语版本,因此可以支持多种语言的应用程序会很棒。
如果您能提供有关在 Android Studio 中从何处开始离线 TextToSpeech 的任何提示,我们将非常感激,谢谢!
试试这个 out.Make 一定要在 xml 布局中添加文本输入框和按钮
import java.util.Locale;
import android.speech.tts.TextToSpeech;
public class TextToSpeech{
private EditText write;
private TextToSpeech t1;
private Button speakbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_text_to_speech );
write = (EditText) findViewById ( R.id.editText );
speakbtn = (Button) findViewById ( R.id.board );
t1 = new TextToSpeech ( getApplicationContext () , new TextToSpeech.OnInitListener () {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage ( Locale.ENGLISH );
}
}
} );
speakbtn.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
String toSpeak = write.getText ().toString ();
Toast.makeText ( getApplicationContext () , toSpeak , Toast.LENGTH_SHORT ).show ();
t1.speak ( toSpeak , TextToSpeech.QUEUE_FLUSH , null );
}
} );
}
@Override
public void onDestroy() {
//Dont forget to shut down text to speech
if (t1 != null) {
t1.stop ();
t1.shutdown ();
}
super.onDestroy ();
}
}
我和我的朋友正在开发一款使用深度学习和神经网络来帮助视障人士的应用程序。我们正在寻找一种方法,将神经网络通过智能手机摄像头获取的信息通过语音返回给用户,因此我们需要进行 TextToSpeech。
然而,对于用户来说,让应用程序离线工作是一个巨大的交易,因为应用程序的所有其他部分都能够运行没有互联网连接(神经网络等)我们'我们正在寻找离线进行 TextToSpeech 的方法。该应用程序也是俄语版本,因此可以支持多种语言的应用程序会很棒。
如果您能提供有关在 Android Studio 中从何处开始离线 TextToSpeech 的任何提示,我们将非常感激,谢谢!
试试这个 out.Make 一定要在 xml 布局中添加文本输入框和按钮
import java.util.Locale;
import android.speech.tts.TextToSpeech;
public class TextToSpeech{
private EditText write;
private TextToSpeech t1;
private Button speakbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_text_to_speech );
write = (EditText) findViewById ( R.id.editText );
speakbtn = (Button) findViewById ( R.id.board );
t1 = new TextToSpeech ( getApplicationContext () , new TextToSpeech.OnInitListener () {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage ( Locale.ENGLISH );
}
}
} );
speakbtn.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
String toSpeak = write.getText ().toString ();
Toast.makeText ( getApplicationContext () , toSpeak , Toast.LENGTH_SHORT ).show ();
t1.speak ( toSpeak , TextToSpeech.QUEUE_FLUSH , null );
}
} );
}
@Override
public void onDestroy() {
//Dont forget to shut down text to speech
if (t1 != null) {
t1.stop ();
t1.shutdown ();
}
super.onDestroy ();
}
}