gpt4 book ai didi

android - 如何在外部存储中将文本转语音文件保存为阿拉伯语的 .wav/.mp3 格式?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:05 25 4
gpt4 key购买 nike

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

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

最佳答案

来自之前的评论:

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(...)

和:

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."

关于android - 如何在外部存储中将文本转语音文件保存为阿拉伯语的 .wav/.mp3 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10393968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com