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).

1  
!747
2  
3  
import android.app.Activity;
4  
import android.speech.tts.*;
5  
6  
m {
7  
  static Activity androidContext;
8  
  static TextToSpeech tts;
9  
  static S text = "Ich bin der Leopold";
10  
  
11  
  p {
12  
    if (args.length != 0 && args[0].length() != 0) text = join(" ", args);
13  
    
14  
    tts = new TextToSpeech(androidContext, new TextToSpeech.OnInitListener() {
15  
      public void onInit(int status) {
16  
        try {
17  
        if (status != TextToSpeech.SUCCESS)
18  
          fail("Speech engine initialization failed");
19  
20  
        int result = tts.setLanguage(Locale.GERMAN);
21  
        if (result == TextToSpeech.LANG_MISSING_DATA
22  
          || result == TextToSpeech.LANG_NOT_SUPPORTED)
23  
          fail("German is not supported");
24  
25  
        result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
26  
          public void onDone(String utteranceId) {
27  
            print("onDone");
28  
            done();
29  
          }
30  
31  
          public void onError(String utteranceId) {
32  
            print("onError");
33  
          }
34  
35  
          public void onStart(String utteranceId) {
36  
          }
37  
        });
38  
        if (result != TextToSpeech.SUCCESS)
39  
          print("Could not set listener");
40  
            
41  
        speak();
42  
        } catch (Throwable e) { e.printStackTrace(); }
43  
      }
44  
    });
45  
  }
46  
  
47  
  static void speak() {
48  
    print(text);
49  
    new HashMap params;
50  
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID");
51  
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
52  
  }
53  
  
54  
  static void done() {
55  
    print("Closing TTS");
56  
    tts.stop();
57  
    tts.shutdown();
58  
    tts = null;
59  
  }
60  
}

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: 523 / 529
Referenced in: [show references]