Сохранение TTS в файл с пользовательским голосом (мужской голос) - PullRequest
0 голосов
/ 28 октября 2019

Я создал ттс мужским голосом, который отлично работает, мой рабочий код:

    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int i) {
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                Voice voiceobj = new Voice("en-us-x-sfg#male_1-local",
                        Locale.getDefault(), 1, 1, false, null);

                tts.setVoice(voiceobj);
                String text = "Hai buddy, how are you?";
                tts.speak(text, TextToSpeech.QUEUE_FLUSH, null,null);

            }

        }


    });

, но я не могу сохранить этот ттс в файл, как .mp3 или .wav. Кто-нибудь есть какие-либо идеи о том, как этого добиться .?

1 Ответ

2 голосов
/ 28 октября 2019

Вы должны использовать synthesizeToFile () .

Voice voiceobj = new Voice("en-us-x-sfg#male_1-local",
        Locale.getDefault(), 1, 1, false, null);

tts.setVoice(voiceobj);
String text = "Hai buddy, how are you?";
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null,null);
Bundle params = new Bundle();
params.putString(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, text);
// Define your destination file.
// Remember to create the directories in which the file will be inserted if they are not created yet.
final String dest = "/path/to/dest/file_name.wav";
// Write it to the specified file.
tts.synthesizeToFile(text, params, dest);
...