问题描述
我创建了一个使用TTS引擎向用户发送反馈的应用程序.为了提高性能,我使用了synthesizeToFile
和addSpeech
方法,但是要合成的文本字符串位于strings.xml
文件内部,因此我必须针对由TTS引擎.
I created an application that uses the TTS engine to send feedback to the user. With the aim to improve the performance, I used the synthesizeToFile
and addSpeech
methods, but strings of text to be synthesized are inside the strings.xml
file, so I have to invoke these methods for each string that is spoken by the TTS engine.
由于TTS引擎仅使用名称以tts_
开头的字符串,是否可以轻松地遍历strings.xml
文件中以tts_
开头的所有字符串?
Since the TTS engine uses only strings whose name begins with tts_
, is it possible to easily iterate over all strings that begin with tts_
within the strings.xml
file?
推荐答案
您可以(在定义时)将所有资源名称都指定为"prefix"+(1..n)
.在代码中,
You can give them all (while defining) the resource name as "prefix"+(1..n)
. And in the code use,
int resid=<constant>;
for(i=1;resid!=0;i++){
resid = this.getResources().getIdentifier("prefix"+i, "strings", this.getPackageName());
}
这篇关于如何轻松地遍历"strings.xml"中的所有字符串.资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!