我怎么能保存文本到语音文件为.wav / mp3格式的外置存储阿拉伯语? [英] How can i save Text to Speech file as .wav/.mp3 format in Arabic language in External Storage?

查看:211
本文介绍了我怎么能保存文本到语音文件为.wav / mp3格式的外置存储阿拉伯语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存音频文件中的阿拉伯语。对于我使用的是下面的code。
我想,但我不能够保存在阿拉伯语。其只保存在英语语言。 请帮帮我,谢谢

 包com.t;

进口的java.io.File;
进口的java.util.HashMap;
进口android.app.Activity;
进口android.os.Bundle;
进口android.os.Environment;
进口android.speech.tts.TextToSpeech;
进口android.speech.tts.TextToSpeech.OnInitListener;
进口android.util.Log;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.EditText;

公共类TextToSpeechNewActivity延伸活动{

按钮存储,播放;
的EditText输入;
字符串speakTextTxt;
TextToSpeech MTTS;
HashMap的<字符串,字符串> myHashRender =新的HashMap<字符串,字符串>();
字符串tempDestFile;
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    店内=(按钮)findViewById(R.id.button1);
    玩=(按钮)findViewById(R.id.button2);
    输入=(EditText上)findViewById(R.id.editText1);
    store.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            speakTextTxt = input.getText()的toString()。
            Log.v(登录,+ input.getText()的toString());

            myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,speakTextTxt);

            字符串exStoragePath = Environment.getExternalStorageDirectory()getAbsolutePath()。
            文件appTmpPath =新的文件(exStoragePath +/普拉迪普);
            appTmpPath.mkdirs();
            字符串tempFilename = input.getText()的toString()+WAV。
            tempDestFile = appTmpPath.getAbsolutePath()+/+ tempFilename;
            新MySpeech(speakTextTxt);

        }
    });
}

类MySpeech实现OnInitListener {

            字符串TTS;

    公共MySpeech(字符串TTS)
    {
        this.tts = TTS;
        MTTS =新TextToSpeech(TextToSpeechNewActivity.this,这一点);
    }

    @覆盖
    公共无效的OnInit(INT状态)
    {
        Log.v(日志,initi);
        mTts.synthesizeToFile(speakTextTxt,myHashRender,tempDestFile);
    }
  }
 }
 

解决方案

从早先的评论:

  

这听起来可能有点明显,但你的语言的尝试明确设置为阿拉伯语区域设置使用<一个href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#setLanguage%28java.util.Locale%29"相对=nofollow> setLanguage(...) ?您可以无形中也首先检查区域设置可通过检查<一个返回值href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#isLanguageAvailable%28java.util.Locale%29"相对=nofollow> isLanguageAvailable(...)

  

让他们从维基百科: ISO 3166-1 ISO 639-1 。请注意, 区域设置文档说:语言codeS两个字母小写的ISO语言codeS(例如en)由ISO 639-1所定义的国家codeS是< STRONG>两个字母大写的ISO国家codeS(如美国),由ISO 3166-1定义。

I want to save audio file in Arabic language. for that I am using the code as below.
i am trying it, but I am not able to save in Arabic language. its saves only in English language. please help me, Thanks

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

解决方案

From earlier comments:

This may sound a little obvious, but have you tried explicitly setting the language to an Arabic Locale using setLanguage(...)? You can potentially also first check if the Locale is available by checking the return value of isLanguageAvailable(...)

And:

Get them from Wikipedia: ISO 3166-1 and ISO 639-1. Do note that the Locale docs say: "The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1. The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1."

这篇关于我怎么能保存文本到语音文件为.wav / mp3格式的外置存储阿拉伯语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆