首页 \ 问答 \ 如何在Android Java上暂停文本到语音(How to Pause Text to Speech on Android Java)

如何在Android Java上暂停文本到语音(How to Pause Text to Speech on Android Java)

目前,我已经实现了文本到语音(TTS)来阅读书籍。 由于TTS只允许最多4000个字符(并且书比其更多)我将书分开并将每个部分添加到TTS队列。 我想能够点击按钮并暂停TTS,然后从用户停止的地方恢复TTS。

我已经尝试使用synthesizeToFile并暂停媒体文件对象,但是你再次只能合成一个小于4000个字符的文件。 我不希望仅为TTS在用户设备上存储数百个媒体文件。

我可以让TTS读完这本书,我不能停下来而不停止它,然后必须从书的开头开始TTS。

在下面的代码中,我将整本书存储在字符串bookText 。 TTS引擎是tts变量。

这是我加载TTS队列的方式:

int position = 0;
int pos = 0;

int sizeOfChar = bookText.length();
String testString = bookText.substring(position,sizeOfChar);

int next = 500;

while(true) {
    String temp = "";

    try {
        temp = testString.substring(pos, next);
        HashMap<String, String> params = new HashMap<String, String>();
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, temp);
        tts.speak(temp, TextToSpeech.QUEUE_ADD, params);

        pos = pos + 500;
        next = next + 500;

    }
    catch (Exception e) {
       temp = testString.substring(pos, testString.length());
       tts.speak(temp, TextToSpeech.QUEUE_ADD, null);
       break;
    }
}

这就是我“停止”TTS的方式:

tts.speak("Pausing!", TextToSpeech.QUEUE_FLUSH, null);

Currently, I have implemented text to speech (TTS) to read Books. Since TTS only allows up to 4000 chars (and a book is wayyyy more than that) I split the book up and add each part to the TTS queue. I wanna be able to click a button and pause the TTS and then later resume the TTS from where the user left off.

I have tried using synthesizeToFile and pausing the media file object but again you can only synthesize one file at a time which is less then 4000 chars. I don't want to have hundreds of media files stored on the users device just for TTS.

I can make the TTS read the book, I just can't pause without stopping it and then having to start the TTS from the beginning of the book.

In the code below, I have the entire book stored in a string bookText. The TTS engine is the tts variable.

This is how I load the TTS queue:

int position = 0;
int pos = 0;

int sizeOfChar = bookText.length();
String testString = bookText.substring(position,sizeOfChar);

int next = 500;

while(true) {
    String temp = "";

    try {
        temp = testString.substring(pos, next);
        HashMap<String, String> params = new HashMap<String, String>();
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, temp);
        tts.speak(temp, TextToSpeech.QUEUE_ADD, params);

        pos = pos + 500;
        next = next + 500;

    }
    catch (Exception e) {
       temp = testString.substring(pos, testString.length());
       tts.speak(temp, TextToSpeech.QUEUE_ADD, null);
       break;
    }
}

This is how I "stop" the TTS:

tts.speak("Pausing!", TextToSpeech.QUEUE_FLUSH, null);

原文:https://stackoverflow.com/questions/49619899
更新时间:2022-05-18 07:05

最满意答案

没有必要从eclipse构建或编译插件。如果你使用ant-build进行构建openfire,那么它可以正常工作。 只需确保安装了Ant并在系统中配置正确的路径。

转到您下载的openfire并将您的插件粘贴到openfire / src / plugin文件夹下。

转到命令行,可以传递命令

ant -f build / build.xml清理openfire插件

或构建您可以传递的特定插件

ant -f build / build.xml clean openfire plugin -Dplugin = nameofyourplugin

在构建之后,您可以在此路径中检查您的插件。

\的Openfire \目标\ Openfire的\插件

谢谢希望这会对你有所帮助。


There is no need to build or compile plugin from eclipse.If you use ant-build for build openfire then it work fine. Just you make sure, Ant is installed and configure proper path in your system.

Go to your downloaded openfire and paste your plugin under openfire/src/plugin folder.

Go command line, you can pass command

ant -f build/build.xml clean openfire plugins

or build specific plugin you can pass

ant -f build/build.xml clean openfire plugin -Dplugin=nameofyourplugin

after building you can check your plugin in this path.

\openfire\target\openfire\plugins

Thanks hope this will help you.

相关问答

更多
  • 不要将下划线用于您的插件名称。 将您的插件重命名为teamFantasianUserServicePlugin。 并获取实例: XMPPServer.getInstance().getPluginManager().getPlugin("teamfantasianuserserviceplugin"); 插件名称应为小写。 Don't use underscores for your plugin name. Rename your Plugin to teamFantasianUserServicePl ...
  • 我无法弄清楚如何使用Gradle做到这一点。 但我确实弄清楚如何用Intellij建造罐子。 我遵循了这个教程: http : //blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ 我浏览了File> Project Structure菜单并添加了两个工件。 一个用我的pluginDefinition / lib文件夹中的所有java代码构建jar,另一个构建一个jar,其中包含我可以在我的Openfire服务器上安装的pluginDe ...
  • 试着用 BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(project,this,artifact); try to use BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(project,this,artifact);
  • Asterisk插件在Openfire 3.10下不起作用。 使用最新的Openfire 3.9。*版本。 你可以在这里下载: Windows(安装程序) http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire_3_9_3.exe Debian http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/op ...
  • 经过大量的研究后,发生了Servlets并不是我应该使用的东西。 相反,对于这种情况,我应该使用IQ Packets,它是XMPP标准的一部分。 一切都围绕着IQHandler : http : IQHandler After doing tons of research, it so happens that Servlets is not what I was supposed to use at all. Instead, for this kind of scenario I should be u ...
  • 嗨,你可以按照我的步骤 得到openfire代码 在源代码中你将获得插件文件夹,你应该把你的插件放在那里。 遵循openfire插件结构。 或者只是复制和修改其中一个插件以简化 然后你可以按照这个链接进行编译。 http://community.igniterealtime.org/docs/DOC-1200 Hi you can follow my steps get openfire code within the source you'll get plugins folder, you should ...
  • 没有必要从eclipse构建或编译插件。如果你使用ant-build进行构建openfire,那么它可以正常工作。 只需确保安装了Ant并在系统中配置正确的路径。 转到您下载的openfire并将您的插件粘贴到openfire / src / plugin文件夹下。 转到命令行,可以传递命令 ant -f build / build.xml清理openfire插件 或构建您可以传递的特定插件 ant -f build / build.xml clean openfire plugin -Dplugin = ...
  • 没有必要从eclipse构建或编译插件。如果你使用ant-build进行构建openfire,那么它可以正常工作。 只需确保安装了Ant并在系统中配置正确的路径。 转到您下载的openfire并将您的插件粘贴到openfire / src / plugin文件夹下。 转到命令行,可以传递命令 ant -f build / build.xml清理openfire插件 或构建您可以传递的特定插件 ant -f build / build.xml clean openfire plugin -Dplugin = ...
  • 在Openfire安装中,在lib目录下,有一个名为的配置文件 log4j.xml 只需修改它并覆盖默认值。 如果您需要log4j教程,请访问: https : //www.mkyong.com/logging/log4j-xml-example 在你的情况下你可以: 在另一个自定义文件中重定向您自己的类 将所有调试重定向到另一个文件中,并将您的自定义类保留在默认调试日志中,以便Openfire Web界面可以使用它 In Openfire installation, under lib director ...
  • 我认为bot尚未针对新版本进行定制,因为您可以在讨论中查看最后发布的帖子中看到它不适用于任何人。但是您可以始终使用smack api创建自己的bot。 创建一个bot ID。 创建一个Java App并使用Smack连接到Openfire 一旦您收到聊天并回复相同的内容,请使用业务逻辑。 I think bot has not been customized for newer versions as you can see in trailing last posts in that discussion ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)