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

49
LINES

< > BotCompany Repo | #1021138 // Say With Language Auto-Detect

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (9080L/48K).

1  
!7
2  
3  
cmodule SayWithLanguageDetect {
4  
  S typingText, text, detectedLanguage;
5  
  
6  
  visualize {
7  
    ret northCenterAndSouthWithMargins(
8  
      dm_bigInputAndSubmit('typingText, "Say / Sag", rThread sayIt),
9  
      fontSizePlus(5, dm_centeredLabel('detectedLanguage)),
10  
      rightAlignedButtons("Correct", rThread correct,
11  
        "Not correct", rThread notCorrect);
12  
  }
13  
  
14  
  void sayIt enter {
15  
    S s = typingText;
16  
    setField(text := s);
17  
    S lang = dm_detectGermanVsEnglish(s);
18  
    print(s + " => " + lang);
19  
    if (eq("de", lang)) {
20  
      setField(detectedLanguage := "Detected as: German");
21  
      dm_sayInGerman(s);
22  
      ret;
23  
    }
24  
    if (eq("en", lang))
25  
      setField(detectedLanguage := "Detected as: English");
26  
    else
27  
      setField(detectedLanguage := "Unknown language");
28  
    dm_sayInEnglish(s);
29  
  }
30  
  
31  
  void correct enter {
32  
    if (!swic(detectedLanguage, "unknown"))
33  
      dm_addWordToLanguageExample(text, lower(lastWord(detectedLanguage)));
34  
  }
35  
  
36  
  void notCorrect enter {
37  
    fS text = this.text;
38  
    inputText("What is the correct language for " + quote(text) + "?", cic(detectedLanguage, "english") ? "german" : "english", voidfunc(S s) {
39  
      dm_addWordToLanguageExample(text, lower(s));
40  
    });
41  
  }
42  
  
43  
  // API
44  
  
45  
  void say(S s) {
46  
    setField(typingText := s);
47  
    sayIt();
48  
  }
49  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021138
Snippet name: Say With Language Auto-Detect
Eternal ID of this version: #1021138/10
Text MD5: 42c25ce52a8c76c3c5817e1cfcf0e42d
Transpilation MD5: 831529a5f0c2c2f531d0d2d265e4df55
Author: stefan
Category: javax / speech
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-23 23:36:07
Source code size: 1352 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 319 / 924
Version history: 9 change(s)
Referenced in: [show references]