【问题标题】:Saving TTS as file with a custom voice (male voice)使用自定义语音(男声)将 TTS 保存为文件
【发布时间】:2019-10-28 19:33:35
【问题描述】:

我创建了一个完美运行的男声 tts,我的工作代码是,

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

            }

        }


    });

但我无法将此 tts 保存到 .mp3 或 .wav 之类的文件中。有人知道如何实现这一目标吗?

【问题讨论】:

    标签: android text-to-speech


    【解决方案1】:

    你必须使用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);
    

    【讨论】:

      猜你喜欢
      • 2016-08-09
      • 2012-04-06
      • 2011-08-11
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多