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

49
LINES

< > BotCompany Repo | #1001175 // Android speech output (internal engine)

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

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

!747

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

m {
  static Activity androidContext;
  static TextToSpeech tts;
  static S text = "Hello Android";
  
  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.US);
        if (result == TextToSpeech.LANG_MISSING_DATA
          || result == TextToSpeech.LANG_NOT_SUPPORTED)
          fail("English is not supported");
       */
            
        speak();
        thread {
          sleepSeconds(20); // to be improved :) (OnUtteranceListener)
          androidContext.runOnUiThread(runnable {
            done();
          });
        }
        } catch (Throwable e) { e.printStackTrace(); }
      }
    });
  }
  
  static void speak() {
    print(text);
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
  }
  
  static void done() {
    print("Closing TTS");
    tts.stop();
    tts.shutdown();
    tts = null;
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001175
Snippet name: Android speech output (internal engine)
Eternal ID of this version: #1001175/1
Text MD5: fe6a8280a8e0a4448468d37100158468
Transpilation MD5: 3c44d6aec9efeade5268c7ea9a202d07
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-06 13:19:34
Source code size: 1264 bytes / 49 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 651 / 673
Referenced in: [show references]