1

hello friends i had created a plugin for unity. the plugin works as creating audio files from text input. i am using default text to speech functionality of android. Sometimes it gives the output properly but sometimes it goes with default voice. how could i sort this out?...... please if anyone had already solved it then please let me know.

If this is unable to solve then please let me know. if there is way to generate audio files from any other engine in android. i am finding the solution which will work offline.

public class TextToSpeechLib extends Application {

private Context mContext;
String Error = "";
public float mSpeed=1f;
public float mPitch=1f;
public boolean _isAvatar = true;
public boolean _doEveryTime = false;
String _voiceNameAvatar = "en-in-x-ahp#male_1-local";
String _voiceNameJudge = "en-in-x-cxx#male_3-local";

public  void DoLog(final Context ctx, final String message){
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show();
        }
    });
}

public void setSppedAndPitch(float speed,float pitch,boolean isAvatar,boolean everyTime,String voice){
    mSpeed = speed;
    mPitch = pitch;
    _isAvatar = isAvatar;
    _doEveryTime = everyTime;
    _voiceNameAvatar = voice;
    }
public void textToAudio(Context ctx, String text,String fileName,String folderName){
    mContext = ctx;
    AsyncTextToSpeech atts = new AsyncTextToSpeech();
    atts.execute(text,fileName,folderName);
}
private  class  AsyncTextToSpeech extends AsyncTask<String,Void,Void>{
    private  String msg;
    private String fileName,folderName;
    TextToSpeech TTS1;

    @Override
    protected Void doInBackground(String... strings) {

        msg = strings[0];
        fileName = strings[1];
        folderName = strings[2];
        TTS1 = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status == TextToSpeech.SUCCESS){





                    for ( Voice tmpVoice : TTS1.getVoices()) {
                        if(_isAvatar) {
                            if (tmpVoice.getName().equals(_voiceNameAvatar)) {

                                TTS1.setVoice(tmpVoice);
                                break;
                            }
                        }else {
                            if (tmpVoice.getName().equals(_voiceNameAvatar)) {
                               TTS1.setVoice(tmpVoice);
                                break;
                            }
                        }


                    }
                    TTS1.setSpeechRate(mSpeed);
                    TTS1.setPitch(mPitch);
                    HashMap<String, String> myHashRender = new HashMap<String, String>();
                    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,msg);
                    File appTmpPath = new File(folderName);
                    appTmpPath.mkdirs();
                    String tempFilename = fileName;
                    String tempDestFile = appTmpPath.getAbsolutePath() + "/"+ tempFilename;
                    final File appTmp = new File(tempDestFile);
                    String utteranceId=this.hashCode() + "";
                    TTS1.synthesizeToFile(msg,null,appTmp,utteranceId);
                                            }
            }
        });
        return null;
    }
}

}

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
sagaa96
  • 11
  • 1
  • With situations like this, your basic choice is either a) maintain total control of the speech engine behavior by embedding a speech engine in your app, or b) give up control and use whatever ("default") engine happens to be installed on the device (there are many all with different behaviors). (https://stackoverflow.com/questions/51510129/android-text-to-speech-api-sounds-robotic) (https://stackoverflow.com/questions/8573030/using-tts-on-android-punctuation-is-read-aloud) – Nerdy Bunz Sep 27 '19 at 20:03
  • It might help if you define "gives the output properly" and describe the exact behavior you are trying to design and why, and/or what behavior you are expecting. – Nerdy Bunz Sep 28 '19 at 20:24
  • @BooberBunz first of all thanks for the reply, I don't wanted to go with the option "b". right now its only behaving like this. i am trying to implement the option "a" in which i ll take care the total control of Speech engine but i am getting stuck at . how can i force user to download the required voice package. as i have basic knowledge android text to speech. can you please give me the reference if any one has already implemented it. – sagaa96 Sep 30 '19 at 05:57

0 Answers0