如何在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 thetts
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
最满意答案
没有必要从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 ...
-
如何在Intellij中使用Gradle构建OpenFire插件?(How do I build an OpenFire plugin using Gradle in Intellij?)[2022-07-16]
我无法弄清楚如何使用Gradle做到这一点。 但我确实弄清楚如何用Intellij建造罐子。 我遵循了这个教程: http : //blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ 我浏览了File> Project Structure菜单并添加了两个工件。 一个用我的pluginDefinition / lib文件夹中的所有java代码构建jar,另一个构建一个jar,其中包含我可以在我的Openfire服务器上安装的pluginDe ... -
如何从插件创建jar?(How to create jar from plugin?)[2023-05-01]
试着用 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 ...
-
Openfire插件servlet(Openfire plugin servlet)[2022-02-04]
经过大量的研究后,发生了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插件(How to Create an OpenFire Plugin)[2022-05-04]
嗨,你可以按照我的步骤 得到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插件创建自己的日志记录配置(How to create my own logging configuration for an Openfire Plugin)[2022-09-12]
在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 ...