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

61
LINES

< > BotCompany Repo | #1027038 - Speech Correlator, simple version (one recording at a time)

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

Uses 795K of libraries. Click here for Pure Java version (5315L/25K).

!7

cmodule SpeechCorrelator1 > DynPrintLog {
  switchable bool react; // react to new recording
  long audioReceived; // timestamp
  S startTime /*, endTime*/;
  new L<Interpretation> interpretations_raw;
  transient L<Interpretation> interpretations;
  //Interpretation bestInterpretation;

  srecord Interpretation(S text, S info, long received) {}
  
  start {
    interpretations = dm_synchroList(interpretations_raw);
    dm_vmBus_answerToMessage dontApplyRecognizedSpeech(() -> react);
    dm_onNewRecording(voidfunc(File f) enter {
      if (!react) ret;
      print("Have WAV: " + f);
      //print(renderFileDateWithSeconds(f));
      setStartTime(extractYMDminusHMS(fileName(f)));

      triggerSpeechRecognitions("wav", f);
    });

    dm_vmBus_onMessage_q newMP3Recording(voidfunc(File f) enter {
      print("Have MP3: " + f);
      setStartTime(extractYMDminusHMS(fileName(f)));
      triggerSpeechRecognitions("mp3", f);
    });

    dm_vmBus_onMessage_q speechRecognized_raw(voidfunc(Map map) enter{
      // module := module(), +info, +text, audioFile := f)
      File f = cast map.get("audioFile");
      S date = extractYMDminusHMS(fileName(f));
      if (!eq(date, startTime)) ret with print("Ignoring speech result for time " + date);
      Interpretation i;
      interpretations.add(i = nu Interpretation(
        text := map.get("text"),
        info := map.get("info"),
        received := now()-audioReceived
      ));
      print("New interpretation (total: " + l(interpretations) + "): " + i);
    });
  }
  
  visual centerAndSouthWithMargins(super,
    jrightaligned(dm_checkBox react()));

  // type = "mp3" or "wav"
  void triggerSpeechRecognitions(S type, File audioFile) {
    
  }

  void setStartTime(S startTime) {
    if (setField(+startTime)) {
      print(+startTime);
      setField(audioReceived := now());
      clear(interpretations);
    }
  }
}

Author comment

Began life as a copy of #1026982

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027038
Snippet name: Speech Correlator, simple version (one recording at a time)
Eternal ID of this version: #1027038/14
Text MD5: 68b46254151e7cfb34dba7f5f64cdb36
Transpilation MD5: 82ae26b33eacd97fabd46738140a922c
Author: stefan
Category: javax / speech recognition
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-13 13:30:39
Source code size: 1909 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 11 / 521
Version history: 13 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1027038 & http://1027038.tinybrain.de