我正在开发一个使用第三方 tts 的应用程序,名为 flite。我正在做类似 tts 说一句话的事情。我想突出显示每个单词。为此,我设法从 tts 获得了单词级别的回调。 工作流程是这样的——按下“说出文本”按钮。它启动了 tt s服务,然后将文本发送到C语言的flite tts,并与应用程序结合在一起。 现在,在 C 代码中,在每个单词之后我都会对两个不同的 Java Activity 进行两次回调: 一个到 tts 服务来说话 第二个是我的测试java activity来突出这个词。 我在我的测试 Activity 中成功获得了单词级别的回调,但之后我无法进行任何 UI 工作。
以下是我收到回调时执行的代码: 这是从 C 代码调用的函数。
private void WordCallback(int isword) {// from
// callback
if (isword == -1) {
Log.d(LOG_TAG, "its not a word");
} else if (isword == -2) {
Log.d(LOG_TAG, "yeah..its the end");
} else {
Log.d(LOG_TAG, "its word no " + isword);
int word = isword;
Log.d(LOG_TAG, "highlightwords");
highlightwords(isword);
if (isword == 4) {
Log.d(LOG_TAG, "in if");
new Thread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "thread started");
try {
Flitetest.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "run on ui");
textview.setText("#" + isword);
}
});
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
}
FliteTest 是 Activity 的名称。 日志打印到“线程启动”,但 runonuithread() 中的代码从未执行,也没有错误。
此外,如果在没有线程和 runonuithread() 的情况下编写 textview.settext("something"),它会给出错误:
致命信号 11(sigsegv) 位于 0x6fc64e87(code=1),线程 20292(SynthThread)。
这种行为的原因是什么?
最佳答案
在 Android ICS (4.0+) 上,如果您的 AndroidManifest.xml 中有 android:anyDensity=false,并且 您已在 ICS 手机上强制启用 GPU 渲染。这也是 native Android 应用程序的问题。
您的选择是不使用 android:anyDensity=false 选项,或者禁用手机上的强制 GPU 渲染。由于您无法在其他人的手机上真正控制后者,因此前者似乎是最佳解决方案。请记住在所有维度上使用“dp”后缀。
关于android runonuithread() 函数不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17525179/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我正在尝试用ruby中的gsub函数替换字符串中的某些单词,但有时效果很好,在某些情况下会出现此错误?这种格式有什么问题吗NoMethodError(undefinedmethod`gsub!'fornil:NilClass):模型.rbclassTest"replacethisID1",WAY=>"replacethisID2andID3",DELTA=>"replacethisID4"}end另一个模型.rbclassCheck 最佳答案 啊,我找到了!gsub!是一个非常奇怪的方法。首先,它替换了字符串,所以它实际上修改了
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只
//1.验证返回状态码是否是200pm.test("Statuscodeis200",function(){pm.response.to.have.status(200);});//2.验证返回body内是否含有某个值pm.test("Bodymatchesstring",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");});//3.验证某个返回值是否是100pm.test("Yourtestname",function(){varjsonData=pm.response.json
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions