ユーザがネットワーク合成音声をデフォルトとして設定すると、私のアプリケーションは、今後のネットワーク待ち時間を防ぐために一般的に発生する要求をキャッシュします。テキスト音声変換システムのデフォルトのピッチとスピーチレート
私のコードhereでこれがどのように行われているかを示しています。要するに、エンジン名と発声を要求に一致させ、一致すれば、TTSエンジンを使用せずにキャッシュされたオーディオをストリーミングします。
その後、Android Text to Speech Settingsでピッチとスピーチレートを変更すると、キャッシュされたオーディオはこれ以上反映されなくなり、無視して再キャッシュするか、それに応じて操作する必要があります。
私の質問:ピッチとスピーチレートのシステムのデフォルト設定を取得するにはどうすればよいですか? に
がピッチ&レートを設定し、公開されたメソッドは、TextToSpeech APIで入手可能である:
/**
* Sets the speech rate.
*
* This has no effect on any pre-recorded speech.
*
* @param speechRate Speech rate. {@code 1.0} is the normal speech rate,
* lower values slow down the speech ({@code 0.5} is half the normal speech rate),
* greater values accelerate it ({@code 2.0} is twice the normal speech rate).
*
* @return {@link #ERROR} or {@link #SUCCESS}.
*/
public int setSpeechRate(float speechRate) {
if (speechRate > 0.0f) {
int intRate = (int)(speechRate * 100);
if (intRate > 0) {
synchronized (mStartLock) {
mParams.putInt(Engine.KEY_PARAM_RATE, intRate);
}
return SUCCESS;
}
}
return ERROR;
}
/**
* Sets the speech pitch for the TextToSpeech engine.
*
* This has no effect on any pre-recorded speech.
*
* @param pitch Speech pitch. {@code 1.0} is the normal pitch,
* lower values lower the tone of the synthesized voice,
* greater values increase it.
*
* @return {@link #ERROR} or {@link #SUCCESS}.
*/
public int setPitch(float pitch) {
if (pitch > 0.0f) {
int intPitch = (int)(pitch * 100);
if (intPitch > 0) {
synchronized (mStartLock) {
mParams.putInt(Engine.KEY_PARAM_PITCH, intPitch);
}
return SUCCESS;
}
}
return ERROR;
}
上記方法は、結合したTTSエンジン(link)のPrivate Bundle
に値を確定もたらす両方ことを考えると:
private final Bundle mParams = new Bundle();
リフレクションを使用して、これらの値がデフォルト/維持されているかどうかを確認しましたバウンドエンジンによって実行される。以下はthe ClassはTextToSpeech
を拡張凝縮例です:
private int getSpeechRate() {
Bundle reflectBundle;
try {
final Field f = this.getClass().getSuperclass().getDeclaredField(TTSDefaults.BOUND_PARAMS);
f.setAccessible(true);
reflectBundle = (Bundle) f.get(this);
if (reflectBundle != null && !reflectBundle.isEmpty()) {
examineBundle(reflectBundle);
if (reflectBundle.containsKey(TTSDefaults.KEY_PARAM_RATE)) {
final int reflectRate = reflectBundle.getInt(TTSDefaults.KEY_PARAM_RATE);
// log
return reflectRate;
} else {
// missing
}
} else {
// empty or null
}
} catch (final NoSuchFieldException e) {
} catch (final IllegalAccessException e) {
} catch (final NullPointerException e) {
}
return -1;
}
/**
* For debugging the bundle extras
*
* @param bundle containing potential extras
*/
private void examineBundle(@Nullable final Bundle bundle) {
if (bundle != null) {
final Set<String> keys = bundle.keySet();
//noinspection Convert2streamapi
for (final String key : keys) {
Log.v(CLS_NAME, "examineBundle: " + key + " ~ " + bundle.get(key));
}
}
}
値が不足しているため、されている、おそらく当然のことながら、これは、彼らが「グローバル」持続しているかではありません。
私が最初にこの問題を解決しようとしたとき、私はそれは些細なことだろうと想定 - 私はそれが事実であると証明願っていますが、私はちょうどツリーの木を見ることができない...のための
感謝この遠くに助けを読んで!
ありがとうございました - 私は気セキュアな設定を探索し、何とかあなたが参照するものを見つけられませんでした...彼らは私のために値を返すされますが、ユーザーが実際にテキスト読み上げの設定でそれらを変更しない限り、彼らはしません(または、アプリケーションが直接セキュア設定を変更する)。おそらくそれがあなたのテストで価値を得ていなかったのでしょうか?私はあなたの答えを少し編集するつもりですので、将来の読者にとってはより簡潔です。あなたが編集に満足していることを知らせてください。私はあなたに賞金を授与します。 – brandall
あなたは正しいです、私はそれらを変更しませんでした。ヌルケースについては言及していない点を除いて、あなたの編集は私にはよく見えます。 nullを取得した場合はどうしますか?TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_PITCHとしますか? –
ああ、もう一度編集する必要があります。それは 'getInt()'でなければなりません。デフォルト値がない場合、例外がスローされます。代替のデフォルト値オプションも追加します。 – brandall