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 addSp
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());
}
You can get all the strings in strings.xml via reflection, and filter out only the ones you need, like so:
for (Field field : R.string.class.getDeclaredFields())
{
if (Modifier.isStatic(field.getModifiers()) && !Modifier.isPrivate(field.getModifiers()) && field.getType().equals(int.class))
{
try
{
if (field.getName().startsWith("tts_"))
{
int id = field.getInt(null);
// do something here...
}
} catch (IllegalArgumentException e)
{
// ignore
} catch (IllegalAccessException e)
{
// ignore
}
}
}
In all my projects, i just observed that the value of strings in R.java starts with 0x7f050000
and it counts upwards, like 0x7f050001, 0x7f050002, 0x7f050003,
....
You could just ++
them :D
Hope it helps :)
You could put these TTS strings into a TypedArray.