TextToSpeech在Android中使用synthesizeToFile时需要花费太多时间

TextToSpeech在Android中使用synthesizeToFile时需要花费太多时间,第1张

概述我使用下面的代码使用Android内置的TTS引擎将.txt文件合成为.mp3文件.码: textToSpeech.synthesizeToFile(readFileText, utterParam, destinationFileName); textToSpeech.setOnUtteranceProgressListener(new Utteran

我使用下面的代码使用Android内置的TTS引擎将.txt文件合成为.mp3文件.

码:

 textToSpeech.synthesizetofile(readfileText,utterParam,destinationfilename); textToSpeech.setonUtteranceProgressListener(new UtteranceProgressListener() {                @OverrIDe                public voID onStart(final String utteranceID) {                    Log.e(TAG,"onStart...");                }                @OverrIDe                public voID onDone(final String utteranceID) {                    Log.e(TAG,"onDone...");                }                @OverrIDe                public voID onError(String utteranceID) {                    Log.e(TAG,"onError...");                }            });

以上是示例代码.
以下是应用程序执行流程:

>从SD卡获取文件
>将文件合成为mp3
>播放mp3文件

问题:文件合成完成后,我只能播放mp3文件.对于大小为1 mb的文件,大约需要1分钟.

我可以做些什么改进吗?

注意:我们需要使用MediaPlayer,因为我们需要播放/暂停阅读器.

谢谢.

最佳答案@H_502_29@我已经解决了这个问题,将整个文件转换成段的段落,并将段落添加到TTS引擎中并直接播放.

 public static String[] convertfiletoparagraph(String fileContent) {//        String pattern = "(?<=(rn|r|n))([ \t]*$)+";        String pattern = "([ \t\r]*\n[ \t\r]*)+";        return Pattern.compile(pattern,Pattern.MulTIliNE).split(fileContent);    }/**     * divIDes files in to paragraphs     */    private voID divIDefiletochunks() {        try {            currentfileChunks = convertfiletoparagraph(fileContent);            currentfileChunks = makeSmallChunks(currentfileChunks);            addChunksTottS();        } catch (Exception e) {            e.printstacktrace();        }    }    /**     * divIDes file paragraphs into sentences of 200 characters     *     * @param currentfileChunks : List of paragraphs     * @return : List of divIDed file     */    private String[] makeSmallChunks(String[] currentfileChunks) {        try {            ArrayList

谢谢. 总结

以上是内存溢出为你收集整理的TextToSpeech在Android中使用synthesizeToFile时需要花费太多时间全部内容,希望文章能够帮你解决TextToSpeech在Android中使用synthesizeToFile时需要花费太多时间所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1139342.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)