Tôi muốn lưu tệp âm thanh bằng tiếng Ả Rập. cho rằng tôi đang sử dụng mã như dưới đây.
tôi đang thử, nhưng tôi không thể lưu bằng tiếng Ả Rập. nó chỉ tiết kiệm bằng tiếng Anh. hãy giúp tôi, Cảm ơnLàm cách nào để lưu tệp Văn bản thành giọng nói dưới định dạng .wav/.mp3 bằng tiếng Ả Rập trong Bộ nhớ ngoài?
package com.t;
import java.io.File;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class TextToSpeechNewActivity extends Activity {
Button store, play;
EditText input;
String speakTextTxt;
TextToSpeech mTts;
HashMap<String, String> myHashRender = new HashMap<String, String>();
String tempDestFile ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
store = (Button) findViewById(R.id.button1);
play = (Button) findViewById(R.id.button2);
input = (EditText) findViewById(R.id.editText1);
store.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
speakTextTxt = input.getText().toString();
Log.v("log", ""+input.getText().toString());
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,speakTextTxt);
String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
File appTmpPath = new File(exStoragePath + "/pradip");
appTmpPath.mkdirs();
String tempFilename = input.getText().toString()+".wav";
tempDestFile = appTmpPath.getAbsolutePath() + "/"+ tempFilename;
new MySpeech(speakTextTxt);
}
});
}
class MySpeech implements OnInitListener{
String tts;
public MySpeech(String tts)
{
this.tts = tts;
mTts = new TextToSpeech(TextToSpeechNewActivity.this, this);
}
@Override
public void onInit(int status)
{
Log.v("log", "initi");
mTts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);
}
}
}
này nghe có vẻ một chút rõ ràng, nhưng bạn đã cố gắng thiết lập một cách rõ ràng ngôn ngữ để một tiếng Ả Rập 'Locale' sử dụng [ 'setLanguage (...)'] (http://developer.android.com/reference /android/speech/tts/TextToSpeech.html#setLanguage%28java.util.Locale%29)? Trước tiên, bạn cũng có thể kiểm tra xem 'Locale' có sẵn hay không bằng cách kiểm tra giá trị trả về của [' isLanguageAvailable (...) '] (http://developer.android.com/reference/android/speech/tts/TextToSpeech. html # isLanguageAvailable% 28java.util.Locale% 29) –
cảm ơn ... tôi đã sử dụng Locale loc = new Locale ("es", "MEX"); \t \t mTts.setLanguage (loc); Đây là cho maxico và mã cho tiếng Ả Rập Saudi? – pradip
Lấy chúng từ Wikipedia: [ISO 3166-1] (http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements) và [ISO 639-1] (http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). Lưu ý rằng ['Locale' docs] (http://developer.android.com/reference/java/util/Locale.html) nói: *" Mã ngôn ngữ là các mã ngôn ngữ ISO chữ thường gồm hai chữ cái (chẳng hạn như " vi ") theo quy định của ISO 639-1. Mã quốc gia là ** hai chữ cái ** mã quốc gia ISO chữ hoa (chẳng hạn như" US ") theo định nghĩa của ISO 3166-1." * –