Author Topic: Text-to-speech in QB64  (Read 6287 times)

0 Members and 1 Guest are viewing this topic.

Offline SquirrelMonkey

  • Newbie
  • Posts: 29
  • Youtuber and GIPHY artist
    • View Profile
    • Joluijten.com
Text-to-speech in QB64
« on: December 28, 2021, 11:35:42 pm »
Hi!

Thanks to the help of hardcore programmers on Discord, I made my first text-to-speech program.
The first lines the program says are, "Hello, this is a test. I would like to thank you."

It is still very primitive.

It reads a phonetic input from a text file and converts it into speech.

The English language contains 19 vowel sounds (5 short vowels, 6 long vowels, 3 diphthongs, 2 oo sounds, and 3 r-controlled vowel sounds) and 25 consonant sounds.

I attempted to make a simple speech generator with these main ingredients. I recorded the sounds.
Of course, language is more complex. There are a lot of phonological processes going on (assimilation, elision, etc.) and there is also intonation, stress, volume and many other processes.

But hey, this is a beginning. I know that there are geniuses on this forum who create chess programs and even moon orbit programs.

My recordings are not great. English is my 3rd language. When it comes to phonetics my English is 2 on the scale of Arnold Schwarzenegger. When it comes to phonology, I know how to improve the program. When it comes to programming not, unfortunately. So feel free to adapt this, improve this, etc.

An example video:

* Speech.zip (Filesize: 6.44 MB, Downloads: 185)

Offline SquirrelMonkey

  • Newbie
  • Posts: 29
  • Youtuber and GIPHY artist
    • View Profile
    • Joluijten.com
Re: Text-to-speech in QB64
« Reply #1 on: December 28, 2021, 11:36:35 pm »
Some additional info that could be useful: https://www.thoughtco.com/sounds-in-english-language-3111166

Offline bombblasterz

  • Newbie
  • Posts: 3
    • View Profile
Re: Text-to-speech in QB64
« Reply #2 on: December 29, 2021, 05:07:56 am »
This is awesome!
T_T#6886

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Text-to-speech in QB64
« Reply #3 on: December 29, 2021, 10:55:27 am »
Ha! I was just praising DIY (and still do) but if it's a choice between 6.48 MB file or a 1-liner Sub:
Code: QB64: [Select]
  1. _Title "Speak test demo" 'b+ 2021-12-29
  2.  
  3. Dim t(1 To 8) As String
  4. t(1) = "A computer once beat me at chess, but it was no match for me at kick boxing."
  5. t(2) = "What did one ocean say to the other ocean? Nothing, they just waved."
  6. t(3) = "A bank is a place that will lend you money, if you can prove that you do not need it."
  7. t(4) = "What is faster, hot or cold? Hot, because you can catch a cold."
  8. t(5) = "Whats the difference between a new husband and a new dog? After a year, the dog is still excited to see you."
  9. t(6) = "Love may be blind, but marriage is a real eye-opener."
  10. t(7) = "I say no to sweets, they dont listen."
  11. t(8) = "Whenever I find the key to success, someone changes the lock."
  12. For i = 1 To 8
  13.     Cls
  14.     Print t(i)
  15.     speak t(i)
  16.     _Delay 1
  17. Print "End of demo."
  18.  
  19. 'Widows only, I think
  20. Sub speak (message As String)
  21.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
  22.  
  23.  

I think I'd lean towards the more practical.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Text-to-speech in QB64
« Reply #4 on: December 29, 2021, 11:14:06 am »
Code: QB64: [Select]
  1. Dim t(1 To 3) As String
  2. t(1) = "Sheesh b +, way to shit in this guys cereal."
  3. t(2) = "Over in the science department, we appreciate this project"
  4. t(3) = "and its good-faith effort to tackle a rather hard problem."
  5. For i = 1 To 3
  6.     Print t(i)
  7.     speak t(i)
  8.     _Delay .1
  9. Sub speak (message As String)
  10.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
You're not done when it works, you're done when it's right.

Offline SquirrelMonkey

  • Newbie
  • Posts: 29
  • Youtuber and GIPHY artist
    • View Profile
    • Joluijten.com
Re: Text-to-speech in QB64
« Reply #5 on: December 29, 2021, 11:50:35 am »

Offline SquirrelMonkey

  • Newbie
  • Posts: 29
  • Youtuber and GIPHY artist
    • View Profile
    • Joluijten.com
Re: Text-to-speech in QB64
« Reply #6 on: December 29, 2021, 12:01:36 pm »
Code: QB64: [Select]
  1.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
  2.  

If text-to-speech were integrated in QB64, I would have agreed with you. Using external software with "shell" takes away the fun of experimenting, imo. Also, it's only 444kb. The ZIP file contains the video as well.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Text-to-speech in QB64
« Reply #7 on: December 29, 2021, 12:04:38 pm »
* * * Very nice. * * *

Works fine with french text (voice clear and understandable)
But for reading french text, you need to remove apostrophe (l'enfant--->lenfant) before sending to speak sub...

I will try this for an epub reader...

Q: Is it possible to modify speed reading ???
Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Text-to-speech in QB64
« Reply #8 on: December 29, 2021, 01:34:53 pm »
If text-to-speech were integrated in QB64, I would have agreed with you. Using external software with "shell" takes away the fun of experimenting, imo. Also, it's only 444kb. The ZIP file contains the video as well.

Yeah not trying to take away from your fun, sorry if I gave that impression.

Just showing a Quick easy to use tool for QB64 on Windows.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Text-to-speech in QB64
« Reply #9 on: December 29, 2021, 01:44:18 pm »
Code: QB64: [Select]
  1. Dim t(1 To 3) As String
  2. t(1) = "Sheesh b +, way to shit in this guys cereal."
  3. t(2) = "Over in the science department, we appreciate this project"
  4. t(3) = "and its good-faith effort to tackle a rather hard problem."
  5. For i = 1 To 3
  6.     Print t(i)
  7.     speak t(i)
  8.     _Delay .1
  9. Sub speak (message As String)
  10.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)

Why is Stx orig post that I quoted before edit not showing in my quote of it???

Can quotes now be changed???

It doesn't even show his post edited. WTH? would I merely quote him quoting my code?
« Last Edit: January 25, 2022, 03:53:32 pm by bplus »

Offline SquirrelMonkey

  • Newbie
  • Posts: 29
  • Youtuber and GIPHY artist
    • View Profile
    • Joluijten.com
Re: Text-to-speech in QB64
« Reply #10 on: December 29, 2021, 02:02:26 pm »
Yeah not trying to take away from your fun, sorry if I gave that impression.
Just showing a Quick easy to use tool for QB64 on Windows.

No problem, I even learned something from your code. Didn't know that you could use Dim that way.
There is even a command prompt way to do Speech-to-Text.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Text-to-speech in QB64
« Reply #11 on: December 29, 2021, 07:16:13 pm »
For Linux, I modified the command to: Shell "espeak " + chr$(34) + message + chr$(34)

Of course, espeak would have to be installed, before hand.... (oh so "mechanical"...)

By the way... very corny jokes... I liked them... lol
Logic is the beginning of wisdom.

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: Text-to-speech in QB64
« Reply #12 on: December 29, 2021, 08:36:59 pm »
I just think this is one of the coolest things ever
BRAVO

I wish I could figure out how it worked... and get some long "ooooooooo..."
recordings to see if i can make them work as a "choir" for my audio software if i mess with the signal chain enough.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Text-to-speech in QB64
« Reply #13 on: January 25, 2022, 03:44:14 pm »
Today I installed the newest QB64 and looked into this new text to speech goody. :) So using B+'s code here, I changed it to an INPUT command so anyone can type anything for the computer to say as the user instead of the programmer. Imagine what we can do with this! Thanks B+ and SquirrelMonkey!

Code: QB64: [Select]
  1. 'Thank you to B+ for the speech code!
  2.  
  3. _Title "Ken's text to speech demo."
  4.  
  5.     Dim t(5) As String
  6.     Input t(i)
  7.     Cls
  8.     Print t(i)
  9.     speak t(i)
  10.     _Delay 1
  11. Loop Until t(i)=""
  12. Print "End of demo."
  13.  
  14. 'Widows only, I think
  15. Sub speak (message As String)
  16.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
  17.  
« Last Edit: January 25, 2022, 03:51:04 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Text-to-speech in QB64
« Reply #14 on: January 25, 2022, 05:40:41 pm »
Like Steve did in my other thread, I added "time" and "date" where it reads the computer time or date depending on what you type.

Code: QB64: [Select]
  1. 'Thank you to B+ for the speech code!
  2.  
  3. _Title "Ken's text to speech demo."
  4.  
  5.     Dim t(5) As String
  6.     Input t(i)
  7.     If t(i) = "date" Or t(i) = "DATE" Or t(i) = "Date" Then t(i) = Date$
  8.     If t(i) = "time" Or t(i) = "TIME" Or t(i) = "Time" Then t(i) = Time$
  9.     Cls
  10.     Print t(i)
  11.     speak t(i)
  12. Loop Until t(i) = ""
  13. Print "End of demo."
  14.  
  15. 'Windows only, I think
  16. Sub speak (message As String)
  17.     Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
  18.  
« Last Edit: January 25, 2022, 05:52:52 pm by SierraKen »