Vocal recognition library

Just starting out? Need help? Post your questions and find answers here.
User avatar
DjPoke
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)
Contact:

Vocal recognition library

Post by DjPoke »

Hello Spider Basic world, :)

I've programmed a Subjective A.I with a very little part of objectivity.
We can talk with it, but that's not the point.

I would like to make a game with multiples differents S.A.I.
I can't use Text To Speech to make them talk, so i'll record what the A.I have to say with different persons voices.

But i would like us to have the possibility to talk to them with Vocal recognition.
So, is there a (free or non expensive) library that i can include into my Spider Basic programs ?
And in this case, is there a tutorial to include a library in a Spider Basic program ?
(I suppose it is in javascript, no ?)

Thanks for your help
My Freewares here :
http://retro-bruno.fr/
User avatar
Arbrakaan
Posts: 91
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva
Contact:

Re: Vocal recognition library

Post by Arbrakaan »

There is JavaScript Web Speech API

https://whatwebcando.today/speech-recognition.html
User avatar
DjPoke
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)
Contact:

Re: Vocal recognition library

Post by DjPoke »

Thanks a lot :)

EDIT:
I've a transcription problem from JS to SpiderBasic with this portion of code :

Code: Select all

Global MikeDisabled.i = 0
Global MikeQuestion.s = ""
Global recognizer.i = 0

EnableJS
  v_recognizer = new webkitSpeechRecognition();
  
  // Reglages de base
  v_recognizer.continuous = true;
  v_recognizer.interimResults = true;
  v_recognizer.lang = 'fr';
  
  // Débuter la reconnaissance !!! PROBLEM HERE !!! The app crashes and there is no debugger
  v_recognizer.onresult = function(event) {
    v_MikeQuestion ='';

    For (var i = event.resultIndex; i < event.results.length; i++) {
      If (event.results[i].isFinal) {
        v_MikeQuestion = event.results[i][0].transcript;
      } Else {
        v_MikeQuestion += event.results[i][0].transcript;
      }
    }
  };

  // Listen For errors
  v_recognizer.onerror = function(event) {
    v_MikeQuestion = 'Erreur de reconnaissance vocale: ' + event.message;
  }
DisableJS

If OpenWindow(#Window, 0, 0, 800, 190, "IAS : Intelligence Artificielle Subjective", #PB_Window_TitleBar | #PB_Window_ScreenCentered)
  TextGadget(#TextQuestion, 10, 10, 780, 25, "Saisissez une question et validez", #PB_Text_Center)
  StringGadget(#StringQuestion, 10, 40, 780, 25, "")
  ButtonGadget(#MikeButton, 290, 70, 100, 25, "Mike")
  ButtonGadget(#OkButton, 410, 70, 100, 25, "Ok")
  TextGadget(#TextAnswer, 10, 130, 780, 25, "Voici votre réponse", #PB_Text_Center)
  StringGadget(#StringAnswer, 10, 160, 780, 25, "", #PB_String_ReadOnly)
  SetActiveGadget(#StringQuestion)
EndIf

DisableGadget(#MikeButton, MikeDisabled)
BindGadgetEvent(#MikeButton, @Mike())
BindGadgetEvent(#OkButton, @Reponse())

My Freewares here :
http://retro-bruno.fr/
User avatar
DjPoke
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)
Contact:

Re: Vocal recognition library

Post by DjPoke »

My window and my gadgets are no more shown because of the "Start speech recognizer" function.
I don't know why. Any idea ?
Also, i would like to access the text of a string gadget in JS... Is it possible ?

EDIT: The problem is with event...

Code: Select all

If OpenWindow(#Window, 0, 0, 800, 190, "IAS : Intelligence Artificielle Subjective", #PB_Window_TitleBar | #PB_Window_ScreenCentered)
  TextGadget(#TextQuestion, 10, 10, 780, 25, "Saisissez une question et validez", #PB_Text_Center)
  StringGadget(#StringQuestion, 10, 40, 780, 25, "")
  ButtonGadget(#MikeButton, 290, 70, 100, 25, "Mike")
  ButtonGadget(#OkButton, 410, 70, 100, 25, "Ok")
  TextGadget(#TextAnswer, 10, 130, 780, 25, "Voici votre réponse", #PB_Text_Center)
  StringGadget(#StringAnswer, 10, 160, 780, 25, "", #PB_String_ReadOnly)
  SetActiveGadget(#StringQuestion)
EndIf

gadgID.i = GadgetID(#StringQuestion)

EnableJS
  try {
    v_recognizer = new webkitSpeechRecognition();
  } catch (e) {
    v_recognizer = Object;
  }
  
  // Base settings
  v_recognizer.continuous = true;
  v_recognizer.interimResults = true;
  v_recognizer.lang = 'fr-FR';
  
  // Start speech recognizer
    v_recognizer.onresult = function(event) {
      var txt = '';
      For (var i = event.resultIndex; i < event.results.length; ++i) {
        txt += event.results[i][0].transcript;
      }
      ; Set here the StringGadget value ??? possible ?  
      gadgID.val(txt)
    };
DisableJS

DisableGadget(#MikeButton, MikeDisabled)
If MikeDisabled = 0
  BindGadgetEvent(#MikeButton, @Mike())
EndIf
BindGadgetEvent(#OkButton, @Reponse())
My Freewares here :
http://retro-bruno.fr/
User avatar
DjPoke
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)
Contact:

Re: Vocal recognition library

Post by DjPoke »

I've found that the "For" JS command is buggy.
I've replaced it by a "While" an the loop works.
My Freewares here :
http://retro-bruno.fr/
Post Reply