Bescottee苦しいときは伸びてるとき、楽なときは伸びていないとき

3 android4.3(API 18)で追加されたTextToSpeechのAPI

admin to Android SDK, development — Tags: ,  

android4.3(API 18)で追加されたTextToSpeechのAPI

以下の2つのAPIがandroid4.3(API 18)で追加されたTextToSpeechのAPIです。

  • Locale getDefaultLanguage()
  • int getMaxSpeechInputLength()

API reference

では、それぞれの API reference を見ていきます。

public Locale getDefaultLanguage ()

Added in API level 18
Returns a Locale instance describing the language currently being used as the default Text-to-speech language.
Returns
language, country (if any) and variant (if any) used by the client stored in a Locale instance, or null on error.

デフォルトのTextToSpeechの言語として利用している現在の設定のLocale instane を返す

public static int getMaxSpeechInputLength ()

Added in API level 18
Limit of length of input string passed to speak and synthesizeToFile.
See Also
speak(String, int, HashMap)
synthesizeToFile(String, HashMap, String)

speakとsynthesizeToFileで出力する入力文字列の長さの上限を返す

Locale getDefaultLanguage()のソースコード
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
/**
 * Returns a Locale instance describing the language currently being used as the default
 * Text-to-speech language.
 *
 * @return language, country (if any) and variant (if any) used by the client stored in a
 *     Locale instance, or {@code null} on error.
 */
public Locale getDefaultLanguage() {
    return runAction(new Action<locale>() {
        @Override
        public Locale run(ITextToSpeechService service) throws RemoteException {
            String[] defaultLanguage = service.getClientDefaultLanguage();
 
            return new Locale(defaultLanguage[0], defaultLanguage[1], defaultLanguage[2]);
        }
    }, null, "getDefaultLanguage");
}
</locale>
getDefaultLanguage() の利用箇所

http://tools.oesf.biz/android-4.3.0_r2.1/xref/packages/apps/Settings/src/com/android/settings/tts/TextToSpeechSettings.java

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Locale defaultLocale = mTts.getDefaultLanguage();
if (defaultLocale == null) {
    Log.e(TAG, "Failed to get default language from engine " + currentEngine);
     return;
 }
 mTts.setLanguage(defaultLocale);
 
 // TODO: This is currently a hidden private API. The intent extras
// and the intent action should be made public if we intend to make this
// a public API. We fall back to using a canned set of strings if this
// doesn't work.
Intent intent = new Intent(TextToSpeech.Engine.ACTION_GET_SAMPLE_TEXT);
 
intent.putExtra("language", defaultLocale.getLanguage());
intent.putExtra("country", defaultLocale.getCountry());
intent.putExtra("variant", defaultLocale.getVariant());
int getMaxSpeechInputLength()のソースコード
1642
1643
1644
1645
1646
1647
1648
1649
1650
/**
 * Limit of length of input string passed to speak and synthesizeToFile.
 *
 * @see #speak
 * @see #synthesizeToFile
 */
public static int getMaxSpeechInputLength() {
    return 4000;
}

入力文字列の上限は、固定値で持たれていて4000文字です。

まとめ(というか、雑感)

新機能追加ではなく、少しだけの改善のようです。最近のAndroid全体の方向性が機能追加ではなく、ユーザや開発者のための改善ということなので、これもその一環かもしれません。
(こんなまとめで申し訳ないです)

1件のコメント »

  1. kurosuke77777 より:

    TextToSpeech for Android4.3

このコメント欄の RSS フィード トラックバック URL

コメントをどうぞ