It is currently Wed Jun 20, 2018 10:36 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: PB.Ex Speech (Windows)
PostPosted: Sat Mar 10, 2018 10:59 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
Hello,

with this library you can use speech recognition (speak -> text) and speech output (text -> speak).
Speech recognition allows you to speak defined words that can be recognized and evaluated by the program. For example, when you speak the word "Basic" an event is triggered and you can react to it.
With the voice output, a text can be read out by the computer voice or stored in an audio file.

Note: I could not test the English speech output, but only the German one.

Functions:
  • TextToSpeaker()
    • Syntax:
      Code:
      Result = TextToSpeaker(Text$, Voice$, Speed, Volume, Asynchronous, @ErrorOutput)

    • Description: Specified text is read by the computer voice.
    • Parameter:
      1. Text$: Text to be read out.
      2. Voice$: When multiple voices are installed on the computer, a specific voice can be set. If "" is specified, the default voice is used.
      3. Speed: Sets the speech speed (-10 (very slow) to 10 (very fast)).
      4. Volume: Sets the volume (0-100).
      5. Asynchronous: If 1 is specified, the program does not wait until the text has been read out completely, but the text is read out in the background.
      6. @ErrorOutput: If an error occurs, the error message is stored in the string variable.
    • Return value:
      • 0: The process was successful.
    • Example:
      Code:
      EnableExplicit

      Define PBEx_Speech

      CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x86.dll")
      CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x64.dll")
      CompilerEndIf

      If PBEx_Speech
        Prototype TextToSpeaker(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, Asynchronous, ErrorOutput)
        Define TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker")
        Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput)
        Define TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile")
        Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput)
        Define SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition")
        Prototype WaitSpeechRecognition(RecognizedWord)
        Define WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition")
        Prototype KillSpeechRecognition()
        Define KillSpeechRecognition.KillSpeechRecognition = GetFunction(PBEx_Speech, "KillSpeechRecognition")
       
        Define ErrorOutput$ = Space(1024)
        If TextToSpeaker("Hello PureBasic friends", "", 1, 100, 0, @ErrorOutput$) <> 0
          Debug ErrorOutput$
        EndIf
       
        CloseLibrary(PBEx_Speech)
      EndIf

  • TextToAudioFile()
    • Syntax:
      Code:
      Result = TextToAudioFile(Text$, Voice$, Speed, Volume, SaveFilePath$, @ErrorOutput)

    • Description: The speech output of the text is stored in the specified audio file (Wave).
    • Parameter:
      1. Text$: Text to be read out.
      2. Voice$: When multiple voices are installed on the computer, a specific voice can be set. If "" is specified, the default voice is used.
      3. Speed: Sets the speech speed (-10 (very slow) to 10 (very fast)).
      4. Volume: Sets the volume (0-100).
      5. SaveFilePath$: Sets the location of the audio file.
      6. @ErrorOutput: If an error occurs, the error message is stored in the string variable.
    • Return value:
      • 0: The process was successful.
    • Example:
      Code:
      EnableExplicit

      Define PBEx_Speech

      CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x86.dll")
      CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x64.dll")
      CompilerEndIf

      If PBEx_Speech
        Prototype TextToSpeaker(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, Asynchronous, ErrorOutput)
        Define TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker")
        Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput)
        Define TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile")
        Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput)
        Define SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition")
        Prototype WaitSpeechRecognition(RecognizedWord)
        Define WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition")
        Prototype KillSpeechRecognition()
        Define KillSpeechRecognition.KillSpeechRecognition = GetFunction(PBEx_Speech, "KillSpeechRecognition")
       
        Define ErrorOutput$ = Space(1024)
        If TextToAudioFile("Hello PureBasic friends", "", 1, 100, "D:\AudioText.wav", @ErrorOutput$) <> 0
          Debug ErrorOutput$
        EndIf
       
        CloseLibrary(PBEx_Speech)
      EndIf

  • SpeechRecognition()
    • Syntax:
      Code:
      Result = SpeechRecognition(WordArray, WordArraySize, @ErrorOutput)

    • Description: Detects the specified words when speaking and returns an event to the WaitSpeechRecognition() function.
    • Parameter:
      1. WordArray: A string array of words to be recognized. If 0 is passed, then any words are recognized.
      2. WordArraySize: Number of elements. If 0 is passed, then any words are recognized.
      3. @ErrorOutput: If an error occurs, the error message is stored in the string variable.
    • Return value:
      • 0: The process was successful.
    • Example:
      Code:
      EnableExplicit

      Define PBEx_Speech

      CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x86.dll")
      CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
        PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x64.dll")
      CompilerEndIf

      If PBEx_Speech
        Prototype TextToSpeaker(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, Asynchronous, ErrorOutput)
        Define TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker")
        Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput)
        Define TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile")
        Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput)
        Define SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition")
        Prototype WaitSpeechRecognition(RecognizedWord)
        Define WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition")
        Prototype KillSpeechRecognition()
        Define KillSpeechRecognition.KillSpeechRecognition = GetFunction(PBEx_Speech, "KillSpeechRecognition")
       
        Define RecognizedWord$ = Space(1024)
        Define ErrorOutput$ = Space(1024)
        Define IsRecognized
        Dim WordArray.s(5)
        WordArray(0) = "Hello"
        WordArray(1) = "Engine"
        WordArray(2) = "Install"
        WordArray(3) = "Basic"
        WordArray(4) = "Welcome"
        WordArray(5) = "Love"
       
        If SpeechRecognition(0, 0, @ErrorOutput$) = 0
          WaitSpeechRecognition(@RecognizedWord$)
          Debug RecognizedWord$
        EndIf
       
        If SpeechRecognition(WordArray(), ArraySize(WordArray())+1, @ErrorOutput$) = 0
          Repeat
            IsRecognized = WaitSpeechRecognition(@RecognizedWord$)
            If IsRecognized = 1
              Debug "Recognized: " + RecognizedWord$
              Break
            ElseIf IsRecognized = 2
              If RecognizedWord$ = ""
                Debug "Nothing was recognized correctly."
              Else
                Debug "Not recognized correctly, maybe this word: " + RecognizedWord$ + "?"
              EndIf
            EndIf
          ForEver
        EndIf
       
        KillSpeechRecognition()
       
        CloseLibrary(PBEx_Speech)
      EndIf

  • WaitSpeechRecognition()
    • Syntax:
      Code:
      Result = WaitSpeechRecognition(@RecognizedWord$)

    • Description: Returns 1 and the word if a specified word is recognized by the SpeechRecognition() function. Or 2 for nothing recognized or similar word.
    • Parameter:
      1. @RecognizedWord$: The recognized word is stored in the string variable. If no correct word is found, it returns either empty or a similar word.
    • Return value:
      • 1: A specified word was detected.
      • 2: Nothing was recognized correctly
  • KillSpeechRecognition()
    • Syntax:
      Code:
      Result = KillSpeechRecognition()

    • Description: Toughly terminates the Windows speech recognition program.
    • Parameter: None
    • Return value:
      • 0: The process was successful.

System requirements:
  • Windows XP or higher
  • .NET Framework 4 or higher
  • Unicode activation (standard from PB 5.50)

License: This DLL file is free of charge and may be used privately and commercially without naming a name and without a link to the homepage.

Download: http://www.rsbasic.de/downloads/downloa ... Speech.zip
I would be happy to receive feedback, suggestions for improvement, bug reports or requests. thank you :)

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Sun Mar 11, 2018 1:35 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3145
Would you be willing to share the DLL source? What speech recognition library are you using? I've been wanting to do something like this with Dragon but never got around to it.

There is so much cool stuff that can be used with speech recognition but there aren't many free libraries available that are easily inter-operable with PureBasic.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Sun Mar 11, 2018 1:40 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
Mistrel wrote:
What speech recognition library are you using?

TextToSpeaker()/TextToAudioFile() :arrow: System.Speech.Synthesis.SpeechSynthesizer() :arrow: System.Speech.dll
SpeechRecognition()/WaitSpeechRecognition() :arrow: System.Speech.Recognition.SpeechRecognizer() :arrow: System.Speech.dll

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Mon Mar 12, 2018 8:07 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
PB.Ex Speech 1.0.1.0 was published.

Changelog:
  • Added: Returns "2" of the WaitSpeechRecognition() function if no correct or similar word was detected.

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Tue Mar 13, 2018 5:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jul 09, 2007 4:47 pm
Posts: 214
Location: Courthouse
Brilliant :!:
Been wanting like this for some time :D

Back to development


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Thu Mar 29, 2018 11:09 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 09, 2011 8:58 am
Posts: 324
Very nice! But is it possible to use voice recognition without having the Microsoft UI visible?

_________________
Yep... Still a noob.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Fri Mar 30, 2018 7:44 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
You mean the little window? Yes, it comes automatically from the interface. Microsoft apparently didn't want the program to eavesdrop, but that the user always sees immediately.
Without this window it is not possible.

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Sun Apr 01, 2018 3:38 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
PB.Ex Speech 1.0.2.0 has been released.

Changelog:
  • Changed: The target.NET framework has been changed from 3.5 to 4.0.
  • Added: KillSpeechRecognition()-Function
  • Added: SpeechRecognition() can now recognize words without predefinition.

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: PB.Ex Speech (Windows)
PostPosted: Tue Apr 03, 2018 5:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 229
Location: France
Thanks for your work.

_________________
~Ar-S~

ResizerGold : The easiest way to resize your pictures and more
My webSite (french) : LDVMULTIMEDIA
PB - 5.4x LTS / 5.6x - W10 x64 - GTX1080 - i5 6600k
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye