7

我想用阿拉伯语保存音频文件。为此,我使用如下代码。
我正在尝试,但我无法以阿拉伯语保存。它仅以英语保存。请帮助我,谢谢

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);
    }
  }
 }
4

1 回答 1

0

从之前的评论:

这听起来可能有点明显,但是您是否尝试过Locale使用明确地将语言设置为阿拉伯语setLanguage(...)?您还Locale可以通过检查的返回值首先检查 是否可用isLanguageAvailable(...)

和:

从 Wikipedia 获取它们:ISO 3166-1ISO 639-1。请注意,Locale文档说:“语言代码是 ISO 639-1 定义的两个字母小写 ISO 语言代码(例如“en”)。国家代码是两个字母大写 ISO 国家代码(例如“US ") 由 ISO 3166-1 定义。

于 2014-01-15T07:36:40.283 回答