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: Select all
Result = TextToSpeaker(Text$, Voice$, Speed, Volume, Asynchronous, @ErrorOutput)
- Description: Specified text is read by the computer voice.
- Parameter:
- Text$: Text to be read out.
- Voice$: When multiple voices are installed on the computer, a specific voice can be set. If "" is specified, the default voice is used.
- Speed: Sets the speech speed (-10 (very slow) to 10 (very fast)).
- Volume: Sets the volume (0-100).
- 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.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global 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) Global TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker") Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput) Global TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile") Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput) Global SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition") Prototype WaitSpeechRecognition(RecognizedWord) Global WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition") Prototype KillSpeechRecognition() Global 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
- Syntax:
- TextToAudioFile()
- Syntax:
Code: Select all
Result = TextToAudioFile(Text$, Voice$, Speed, Volume, SaveFilePath$, @ErrorOutput)
- Description: The speech output of the text is stored in the specified audio file (Wave).
- Parameter:
- Text$: Text to be read out.
- Voice$: When multiple voices are installed on the computer, a specific voice can be set. If "" is specified, the default voice is used.
- Speed: Sets the speech speed (-10 (very slow) to 10 (very fast)).
- Volume: Sets the volume (0-100).
- SaveFilePath$: Sets the location of the audio file.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global 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) Global TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker") Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput) Global TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile") Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput) Global SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition") Prototype WaitSpeechRecognition(RecognizedWord) Global WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition") Prototype KillSpeechRecognition() Global 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
- Syntax:
- SpeechRecognition()
- Syntax:
Code: Select all
Result = SpeechRecognition(WordArray, WordArraySize, @ErrorOutput)
- Description: Detects the specified words when speaking and returns an event to the WaitSpeechRecognition() function.
- Parameter:
- WordArray: A string array of words to be recognized. If 0 is passed, then any words are recognized.
- WordArraySize: Number of elements. If 0 is passed, then any words are recognized.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 0: The process was successful.
- Example:
Code: Select all
EnableExplicit Global 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) Global TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker") Prototype TextToAudioFile(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, SaveFilePath.p-Unicode, ErrorOutput) Global TextToAudioFile.TextToAudioFile = GetFunction(PBEx_Speech, "TextToAudioFile") Prototype SpeechRecognition(WordArray, WordArraySize, ErrorOutput) Global SpeechRecognition.SpeechRecognition = GetFunction(PBEx_Speech, "SpeechRecognition") Prototype WaitSpeechRecognition(RecognizedWord) Global WaitSpeechRecognition.WaitSpeechRecognition = GetFunction(PBEx_Speech, "WaitSpeechRecognition") Prototype KillSpeechRecognition() Global 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
- Syntax:
- WaitSpeechRecognition()
- Syntax:
Code: Select all
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:
- @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
- Syntax:
- KillSpeechRecognition()
- Syntax:
Code: Select all
Result = KillSpeechRecognition()
- Description: Toughly terminates the Windows speech recognition program.
- Parameter: None
- Return value:
- 0: The process was successful.
- Syntax:
- Windows XP or higher
- .NET Framework 4 or higher
- Unicode activation (standard from PB 5.50)
The following copyright texts must be provided:
Download: https://www.rsbasic.de/downloads/downlo ... Speech.zipCopyright © 2019 RSBasic.de
I would be happy to receive feedback, suggestions for improvement, bug reports or requests. If you want to support me, you can also donate me a little something. Thank you