栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

我如何在freetts中将输出语音存储到音频文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

我如何在freetts中将输出语音存储到音频文件

我想出了方法,您只需要简单地使用

SingleFileAudioPlayer
传递文件名和文件类型,样本声明就应该像这样:

audioPlayer = new SingleFileAudioPlayer("output",Type.WAVE);

现在您需要将

SinglefileAudioplayer
对象附加到您的
VoiceManager
对象:例如

helloVoice.setAudioPlayer(audioPlayer);

现在使用:

hellovoice.speak("zyxss");

这样会保存文件以及任何说话内容。请记住关闭音频播放器,否则文件将不会保存。

audioPlayer.close();
退出前放 。

这是完整的工作代码,它将转储到您的C目录中

        import com.sun.speech.freetts.FreeTTS;    import com.sun.speech.freetts.Voice;    import com.sun.speech.freetts.VoiceManager;    import com.sun.speech.freetts.audio.AudioPlayer;    import com.sun.speech.freetts.audio.SingleFileAudioPlayer;    import javax.sound.sampled.AudioFileFormat.Type;        public class FreeTTSHelloWorld {                public static void main(String[] args) {// listAllVoices(); FreeTTS freetts;       AudioPlayer audioPlayer = null; String voiceName = "kevin16"; System.out.println(); System.out.println("Using voice: " + voiceName);  VoiceManager voiceManager = VoiceManager.getInstance(); Voice helloVoice = voiceManager.getVoice(voiceName); if (helloVoice == null) {     System.err.println(         "Cannot find a voice named "         + voiceName + ".  Please specify a different voice.");     System.exit(1); }  helloVoice.allocate(); //create a audioplayer to dump the output fileaudioPlayer = new SingleFileAudioPlayer("C://output",Type.WAVE);    //attach the audioplayer helloVoice.setAudioPlayer(audioPlayer); helloVoice.speak("Thank you for giving me a voice. "       + "I'm so glad to say hello to this world.");  helloVoice.deallocate();//don't forget to close the audioplayer otherwise file will not be saved audioPlayer.close(); System.exit(0);        }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/463787.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号