Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1001300 // Android speech output, german, testing

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (124L/2K/5K).

!747

import android.app.Activity;
import android.speech.tts.*;

m {
  static Activity androidContext;
  static TextToSpeech tts;
  static S text = "Ich bin der Leopold";
  
  p {
    if (args.length != 0 && args[0].length() != 0) text = join(" ", args);
    
    tts = new TextToSpeech(androidContext, new TextToSpeech.OnInitListener() {
      public void onInit(int status) {
        try {
        if (status != TextToSpeech.SUCCESS)
          fail("Speech engine initialization failed");

        int result = tts.setLanguage(Locale.GERMAN);
        if (result == TextToSpeech.LANG_MISSING_DATA
          || result == TextToSpeech.LANG_NOT_SUPPORTED)
          fail("German is not supported");

        result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
          public void onDone(String utteranceId) {
            print("onDone");
            done();
          }

          public void onError(String utteranceId) {
            print("onError");
          }

          public void onStart(String utteranceId) {
          }
        });
        if (result != TextToSpeech.SUCCESS)
          print("Could not set listener");
            
        speak();
        } catch (Throwable e) { e.printStackTrace(); }
      }
    });
  }
  
  static void speak() {
    print(text);
    new HashMap params;
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID");
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
  }
  
  static void done() {
    print("Closing TTS");
    tts.stop();
    tts.shutdown();
    tts = null;
  }
}

Author comment

Began life as a copy of #1001253

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, ufhdzwgrioxs, vouqrxazstgt

No comments. add comment

Snippet ID: #1001300
Snippet name: Android speech output, german, testing
Eternal ID of this version: #1001300/1
Text MD5: b1046bc42af8143031c6f65f7f5a0165
Transpilation MD5: 6d32c2dace1c8ea0bda040e39baf9d2c
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-07 21:10:35
Source code size: 1627 bytes / 60 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 584 / 609
Referenced in: [show references]