我正在编写一个可以用日语发短信的应用程序。但是,当我编码时,我知道Android不支持日语。 我尝试使用SVOX。但是,它不是最好的解决方案吗? 你能帮我解决我的问题吗? 谢谢你。
这是@ErsinGülbahar帮助后的代码:)
package com.example.tts;
import java.io.IOException;
import java.util.Locale;
import org.apache.http.util.LangUtils;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends Activity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
MediaPlayer mediaPlayer;
Thread x;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
x = new Thread() {
public void run() {
try {
String url1 = "http://www.translate.google.com/translate_tts?ie=UTF-8&q="
+ "Hello".replace(' ', '+').replace('\n', '.')
+ "%0A&tl=" + "ja" + "&prev=input";
String url2 = "http://www.translate.google.com/translate_tts?ie=UTF-8&q=nihongo%0A&tl=ja&prev=input";
mediaPlayer = new MediaPlayer();
mediaPlayer.reset();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url2);
mediaPlayer.prepare(); // might take long! (for buffering,
// etc)
mediaPlayer.start();
} catch (IllegalArgumentException e) {
mediaPlayer.reset();
} catch (IllegalStateException e) {
mediaPlayer.reset();
} catch (IOException e) {
mediaPlayer.reset();
}
finally {
}
}
};
ImageButton ibm = (ImageButton) findViewById(R.id.imageButton1);
ibm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Callme", 4).show();
x.run();
}
});
}
@Override
public void onInit(int arg0) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:1)
这是列表
Language / Locale Supported since version English, US (en_US) 1.1 German, Germany (de_DE) 1.1 Chinese, PRC (zh_CN) 1.5 Chinese, Taiwan (zh_TW) 1.5 Czech, Czech Republic (cs_CZ) 1.5 Dutch, Belgium (nl_BE) 1.5 Dutch, Netherlands (nl_NL) 1.5 English, Australia (en_AU) 1.5 English, Britain (en_GB) 1.5 English, Canada (en_CA) 1.5 English, New Zealand (en_NZ) 1.5 English, Singapore(en_SG) 1.5 French, Belgium (fr_BE) 1.5 French, Canada (fr_CA) 1.5 French, France (fr_FR) 1.5 French, Switzerland (fr_CH) 1.5 German, Austria (de_AT) 1.5 German, Liechtenstein (de_LI) 1.5 German, Switzerland (de_CH) 1.5 Italian, Italy (it_IT) 1.5 Italian, Switzerland (it_CH) 1.5 Japanese (ja_JP) 1.5 Korean (ko_KR) 1.5 Polish (pl_PL) 1.5 Russian (ru_RU) 1.5 Spanish (es_ES) 1.5 Arabic, Egypt (ar_EG) 2.3 Arabic, Israel (ar_IL) 2.3 Bulgarian, Bulgaria (bg_BG) 2.3 Catalan, Spain (ca_ES) 2.3 Croatian, Croatia (hr_HR) 2.3 Danish, Denmark(da_DK) 2.3 English, India (en_IN) 2.3 English, Ireland (en_IE) 2.3 English, Zimbabwe (en_ZA) 2.3 Finnish, Finland (fi_FI) 2.3 Greek, Greece (el_GR) 2.3 Hebrew, Israel (iw_IL)* 2.3 Hindi, India (hi_IN) 2.3 Hungarian, Hungary (hu_HU) 2.3 Indonesian, Indonesia (in_ID)* 2.3 Latvian, Latvia (lv_LV) 2.3 Lithuanian, Lithuania (lt_LT) 2.3 Norwegian-Bokmol, Norway(nb_NO) 2.3 Portuguese, Brazil (pt_BR) 2.3 Portuguese, Portugal (pt_PT) 2.3 Romanian, Romania (ro_RO) 2.3 Serbian (sr_RS) 2.3 Slovak, Slovakia (sk_SK) 2.3 Slovenian, Slovenia (sl_SI) 2.3 Spanish, US (es_US) 2.3 Swedish, Sweden (sv_SE) 2.3 Tagalog, Philippines (tl_PH) 2.3 Thai, Thailand (th_TH) 2.3 Turkish, Turkey (tr_TR) 2.3 Ukrainian, Ukraine (uk_UA) 2.3 Vietnamese, Vietnam (vi_VN) 2.3
答案 1 :(得分:0)
你可以定义一个帖子:
Thread x=new Thread(){ public void run(){
try{
url1="http://www.translate.google.com/translate_tts?ie=UTF-8&q="+word_which_read.replace(' ','+' ).replace('\n','.' )+"%0A&tl="+language+"&prev=input";
mediaPlayer=new MediaPlayer();
mediaPlayer.reset();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url1);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
} catch (IllegalArgumentException e) {
mediaPlayer.reset();
} catch (IllegalStateException e) {
mediaPlayer.reset();
} catch (IOException e) {
mediaPlayer.reset();
}
finally{
// x.suspend();
}
}
};
您可以致电x.run();
在网址中,您应将语言设置为ja
这是日语。
你应该将* word_which_read *设置为 word