QB64.org Forum

Active Forums => Programs => Topic started by: SirCrow on November 20, 2018, 12:59:21 pm

Title: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 12:59:21 pm
I wrote this specifically to be used in my StarBlast game to generate semi-random chatter or dialogue (typical sci-fi technical jargon, as on-screen text) between the pilots of the asteroid-blasting spacecraft.  In the game itself, the communication also involves their leader/commander, as well as their base of operations, Central Command.

Code: QB64: [Select]
  1.  
  2. _FULLSCREEN ': DEFINT A-Z
  3.  
  4.     GOSUB Tech_Talk: COLOR 7, 0
  5.     PRINT Chat$: Cnt = Cnt + 1
  6.     IF Cnt = 22 THEN COLOR 11: PRINT "[Esc] to exit; other key to continue";: SLEEP: Cnt = 0: CLS
  7.     'IF INSTR(Chat$, "seems") THEN SLEEP
  8.     'IF INSTR(Chat$, "mother") THEN SLEEP
  9.     'IF INSTR(Chat$, "burp") THEN SLEEP
  10. LOOP UNTIL INKEY$ = CHR$(27): END '======================================================
  11.  
  12.  
  13. '###########################################################################################################
  14.  
  15. Chat_Opener: 'First letter must be capital (but addition of "Commander, " will LCASE it.)
  16. DATA I believe,"I don't know why, but",I think,It seems,"For some reason,","Oddly,","Okay,"
  17. DATA "I don't get it....",Strange....,This is odd....,This is weird....
  18. DATA XXX
  19.  
  20. Tech_Adj:
  21. DATA adaptive,antimatter,asymmetric,barometric,bilateral,binary,biogenic,central,continuous,dimensional,directional
  22. DATA external,forward,gravitational,hi-res,high-level,hypersensitive,internal,ionic,isolinear,lateral,level-1,logical
  23. DATA long-range,low-gain,low-level,low-magnitude,low-tolerance
  24. DATA multidirectional,multiphasic,multispectral,primary,radial,redundant,repeating,reverse,secondary,spatial,spectral
  25. DATA stage-3,temporal,tri-level,tri-stage,vertical,zero-point
  26. DATA XXX
  27.  
  28. Tech_Noun_1:
  29. DATA alignment,contrast,convergence,echo,frequency,impulse,latitude,particle,pressure,quantum,resistance
  30. DATA resonance,tachyon,wavelength
  31. DATA ABX,ACE,AGT,CR-52,DST-35,LTS-1804,MX-44,PU-36: 'Thanks, Marvin the Martian!
  32. DATA XXX
  33.  
  34. Tech_Noun_2:
  35. DATA analyser,computer,coupler,decoupler,detector,decoupler,stabiliser
  36. DATA XXX
  37.  
  38. Chat_Closer:
  39. DATA has decided to reset itself,has gone all screwy on me,has gone offline,has just shut down,has shut down
  40. DATA is acting funny,is acting up,is malfunctioning,is on the fritz,keeps cutting my engines,recommends recalibration
  41. DATA says I need to reset it,says I need to shut it down,says I should recalibrate it
  42. DATA seems to be faulty,seems to have reset itself,seems to be shutting down
  43. DATA wants to recalibrate,wants to reset itself,wants to shut down
  44. DATA has just insulted my mother,just burped,just farted: 'Far below, "IF RN > C - 3" refers to these 3 items
  45. DATA XXX
  46. '############################################################################################################
  47.  
  48.  
  49. DataCount:
  50. C = 0: DO: READ D$: C = C + 1: LOOP UNTIL D$ = "XXX": D$ = "": C = C - 1
  51.  
  52.  
  53. Tech_Talk: 'Here, we'll assemble a "tech thing" using parts randomly selected from
  54. '           Tech Adjective and Tech Noun (2), with the option of a middle Noun (1).
  55. '           This Tech Thing will be inserted into a line of Pilot dialogue.
  56.  
  57.  
  58. IF RND < .5 THEN Chat$ = "My " ELSE Chat$ = "The " 'Optional possessive pronoun or definite article
  59.  
  60.  
  61. IF RND < .4 THEN 'Optional Opener <><><><><><><><><><><><><><><><><><><><><><><><><>
  62.  
  63.     RESTORE Chat_Opener: GOSUB DataCount 'Count the line openers
  64.     'Get_Open:
  65.     RESTORE Chat_Opener: FOR D = 1 TO RND * C + 1: READ D$: NEXT: D = 0 ': IF D$ = "" OR D$ = "XXX" GOTO Get_Open
  66.  
  67.     IF RIGHT$(D$, 3) <> "..." THEN D$ = D$ + " "
  68.     Chat$ = D$ + LCASE$(Chat$)
  69. END IF '<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  70.  
  71.  
  72.  
  73. IF RND < .4 THEN 'Optionally, pilot addresses Commander <><><><><><><><><><><><><><>
  74.     IF LEFT$(Chat$, 2) <> "I " THEN Chat$ = LCASE$(Chat$)
  75.     Chat$ = "Commander, " + Chat$
  76. END IF '<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  77.  
  78.  
  79. RESTORE Tech_Adj: GOSUB DataCount 'Count the adjectives
  80. 'Get_Adj:
  81. RESTORE Tech_Adj: FOR D = 1 TO RND * C + 1: READ D$: NEXT: D = 0 ': IF D$ = "" OR D$ = "XXX" GOTO Get_Adj
  82.  
  83. Chat$ = Chat$ + D$ + " " '================================================================
  84.  
  85.  
  86. IF RND < .6 THEN 'Optional middle noun  <><><><><><><><><><><><><><><><><><><><><><>
  87.     RESTORE Tech_Noun_1: GOSUB DataCount
  88.     'Get_Noun1:
  89.     RESTORE Tech_Noun_1: FOR D = 1 TO RND * C + 1: READ D$: NEXT: D = 0 ': IF D$ = "" OR D$ = "XXX" GOTO Get_Noun1
  90.  
  91.     Chat$ = Chat$ + D$ + " "
  92. END IF '<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  93.  
  94.  
  95. RESTORE Tech_Noun_2: GOSUB DataCount
  96. 'Get_Noun2:
  97. RESTORE Tech_Noun_2: FOR D = 1 TO RND * C + 1: READ D$: NEXT: D = 0 ': IF D$ = "" OR D$ = "XXX" GOTO Get_Noun2
  98. Chat$ = Chat$ + D$ + " " '================================================================
  99.  
  100. IF INSTR(Chat$, "binary computer") GOTO Tech_Talk 'Avoid really silly Tech Things
  101. IF INSTR(Chat$, "continuous computer") GOTO Tech_Talk
  102.  
  103. RESTORE Chat_Closer: GOSUB DataCount 'Count the line enders
  104. Get_Close:
  105. RN = RND * C + 1: IF RN > C - 3 AND RND < .92 GOTO Get_Close 'Limit occurrences of silly closers
  106. RESTORE Chat_Closer: FOR D = 1 TO RN: READ D$: NEXT: D = 0 ': IF D$ = "" OR D$ = "XXX" GOTO Get_Close
  107.  
  108. IF INSTR(Chat$, "seems") > 0 AND INSTR(D$, "seems") > 0 GOTO Get_Close 'Don't have "seems" twice in a line
  109. IF INSTR(Chat$, "I believe") > 0 AND INSTR(D$, "seems") > 0 GOTO Get_Close 'This is also dumb
  110. IF INSTR(Chat$, "I think") > 0 AND INSTR(D$, "seems") > 0 GOTO Get_Close
  111.  
  112. Chat$ = Chat$ + D$ '======================================================================
  113.  
  114. 'Maybe add an optional closer-closer...
  115.  
  116. IF RND < .4 THEN Chat$ = Chat$ + " again"
  117. IF RND < .5 THEN Chat$ = Chat$ + "." ELSE Chat$ = Chat$ + "!" 'And there's your Pilot's dialogue!
  118.  
  119.  
  120.  

By the way, can someone explain why, when I enable the DEFINT A-Z at the top, the end-of-data marker (XXX) will show up in some of the lines of text?  I know I should know this, but...
Thanks.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: johnno56 on November 20, 2018, 01:55:30 pm
Very cool... I particularly like the 'comedy' remarks, "gone all screwy","acting funny","on the fritz" - I was expecting "Star Trek" type comments but was pleasantly surprised by the 'slang'... Well done!

J
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 20, 2018, 02:03:10 pm
You're taking a fraction (RND) and multiplying by an integer then assigning it to the variable D. D will be rounded up if you define it as an integer by DEFINT A-Z, which means it will go as high as 8, which is the XXX in the noun2 data field.

Here, try running this example with and without DEFINT A-Z

Code: QB64: [Select]
  1. DEFINT A-Z
  2. FOR d = .9 TO 5: PRINT d: NEXT
  3. FOR i = 1 TO 4.9 ' Will print to 5 if DEFINT A-Z is utilized, to 4 if not.
  4.     PRINT i
  5. FOR i = 1 TO 5
  6.     PRINT i

See what I mean?

Pete
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 02:14:52 pm
You're taking a fraction (RND) and multiplying by an integer then assigning it to the variable D. D will be rounded up if you define it as an integer by DEFINT A-Z, which means it will go as high as 8, which is the XXX in the noun2 data field.

Here, try running this example with and without DEFINT A-Z

Code: QB64: [Select]
  1. DEFINT A-Z
  2. FOR d = .9 TO 5: PRINT d: NEXT
  3. FOR i = 1 TO 4.9 ' Will print to 5 if DEFINT A-Z is utilized, to 4 if not.
  4.     PRINT i
  5. FOR i = 1 TO 5
  6.     PRINT i

See what I mean?

Pete

Thanks, Pete.  I had already figured it had to be the fraction/integer thing;  I just hadn't yet located the exact one.  I see now that it's at the FOR-NEXT loops.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 02:19:48 pm
Very cool... I particularly like the 'comedy' remarks, "gone all screwy","acting funny","on the fritz" - I was expecting "Star Trek" type comments but was pleasantly surprised by the 'slang'... Well done!

J

Thanks!  Glad you liked it.  Keep running it and eventually you'll see the funniest of the funny, methinks. I've limited their usage, as it seems a bit inappropriate that a space pilot on a serious mission should talk that way.  Only slightly vulgar, mind you.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 08:06:51 pm
It's so funny, while testing the technical-jargon generator, I have it set to display the various (make-believe) voice-to-text messages much more frequently than it'll be once testing is done.  It's all Commander this, Commander that in rapid succession.  I'd hate to be that commander.  No doubt he/she would either quit very early or just start blasting his/her own pilots' ships to bits.
Anyway, I hope to upload this new version of StarBlast pretty soon.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 20, 2018, 08:23:34 pm
I'm sure President Trump could sympathize. Have you considered downloading some sort of text to speech app and shelling the messages?

Pete
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 11:03:10 pm
I'm sure President Trump could sympathize. Have you considered downloading some sort of text to speech app and shelling the messages?

Pete

That's quite an idea.  If I can find something entirely free and easy to use, I may just do that.  Thanks.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 20, 2018, 11:17:10 pm
This looked interesting: http://jampal.sourceforge.net/ptts.html
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SMcNeill on November 20, 2018, 11:31:19 pm
In Windows, you should be able to use a powershell script with the built in text-to-speech.   

Create a script called "speak.psl"  (PSL for Power Script Language, not ps1 as the number 1.  Sometimes it's hard to tell the difference depending on font.)

Code: QB64: [Select]
  1. param([string]$inputText)
  2. Add-Type –AssemblyName System.Speech
  3. $synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
  4. $synth.Speak($inputText);

Then you can call it from the command line (or QB64 SHELL) with:

.\speak.psl "I'm sorry Dave, I'm afraid I can't do that"
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 20, 2018, 11:47:59 pm
I'm using Ubuntu.  I'll look into it and come back here for help if I need it.  Thanks.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 20, 2018, 11:51:19 pm
The link I provided...

"For Linux or CYGWIN installations, there is a script file (ptts.sh) which provides everything here but supports many speech engines and languages. Run ptts.sh --help to get information on it. Note that under Linux the Microsoft speech engine will not work, another speech engine must be installed. "
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 23, 2018, 03:21:18 am
The link I provided...

"For Linux or CYGWIN installations, there is a script file (ptts.sh) which provides everything here but supports many speech engines and languages. Run ptts.sh --help to get information on it. Note that under Linux the Microsoft speech engine will not work, another speech engine must be installed. "

Thanks.  I just hope I won't find all of this too daunting.  I do suffer a bit of old dog, new tricks, y'know.  More than a bit, really.
I'm encouraged, though, by the fact that, before I made my really cool Asteroids knock-off, I wouldn't have imagined incorporating multi-layered moving backgrounds in any of my programs.

EDIT: I've installed eSpeak and, without too much trouble, got it to work in my game.  Some people claim that MaryTTS produces much better voices, but I've had much trouble getting that to work.  Also, I have no idea whether my prog. code, as it stands now, would produce speech when run under Windows.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 23, 2018, 06:36:57 pm
I fully understand the daunting part. That has actually put me off from trying Linux, but I'm getting pressured by Microsoft's transition to their BS app plan.

I'm glad you found a voice solution with eSpeak. That should add some punch to your game. If text to speech was available in the 1980's, I would have had a field day using it.

Please keep us posted n how the project is coming along.

Pete

Title: Re: Sci-Fi Techno-Babble Generator
Post by: luke on November 23, 2018, 06:50:28 pm
If you're not willing to muck around with that, there's a program called festival that does TTS on Linux. "sudo apt-get install festival" then "festival --tts file.txt".
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 23, 2018, 07:33:26 pm
. . . I'm glad you found a voice solution with eSpeak. That should add some punch to your game. If text to speech was available in the 1980's, I would have had a field day using it.

Please keep us posted n how the project is coming along.

I'll gladly keep you guys posted.  Currently, I've enabled the voice only for messages from Central Command;  otherwise, there's just too much of that robot-like chatter going on.  I've tried both the British and American accents, and they're both hard to take seriously.  Ha-ha.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 23, 2018, 07:36:24 pm
If you're not willing to muck around with that, there's a program called festival that does TTS on Linux. "sudo apt-get install festival" then "festival --tts file.txt".

Yes, I've seen mention of Festival.  I forget, is it supposed to be superior to eSpeak?  I'm trying to install Festival right now...

UPDATE: I've managed to get Festival working in the game.  I think I like it a little more than eSpeak.  Now if I could just get it to not pronounce AG and SR as ag and senior (without inserting hyphens), I'd like it even more!  I do like that it says 054-mark-093 as zero-5-4 mark zero-9-3, while eSpeak says zero-54-mark-zero-93. However, eSpeak lets me adjust the volume, while Festival doesn't appear to have that ability.

Thanks for the Terminal command lines to install Festival;  it made the process quite easy.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 23, 2018, 08:05:30 pm
You can add the hyphen as an invisible character.

Let's say a$ = "This is a te-st"
Send that to Festival and then use a screen printer like...

FOR i = 1 to len(A$)
IF MID$(a$, i, 1) <> "-" the print a$;
NEXT

That would give you the best of both.

Pete
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 23, 2018, 08:11:47 pm
You can add the hyphen as an invisible character.

Let's say a$ = "This is a te-st"
Send that to Festival and then use a screen printer like...

FOR i = 1 to len(A$)
IF MID$(a$, i, 1) <> "-" the print a$;
NEXT

That would give you the best of both.

Pete

Possibly, I can make that work.  Thanks.  But first, I want to teach it to randomly generate those Star Trek-like bearing numbers.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: luke on November 23, 2018, 08:45:50 pm
use a screen printer like...

FOR i = 1 to len(A$)
IF MID$(a$, i, 1) <> "-" the print a$;
NEXT
Even better, you can stick a _DELAY in the and get the universally-annoying teletype printing effect. Bonus points if you can find a corny sound effect to go with it.
Title: Re: Sci-Fi Techno-Babble Generator
Post by: Pete on November 23, 2018, 10:40:26 pm
Been there, done that some 20 years ago. Used QBasic SOUND to make clicks that sounded like a typewriter. I had to use TIMER to make a delay loop that was less than SLEEP 1, so I'm definitely a fan of the _DEAY keyword.

Pete
Title: Re: Sci-Fi Techno-Babble Generator
Post by: SirCrow on November 23, 2018, 11:01:51 pm
use a screen printer like...

FOR i = 1 to len(A$)
IF MID$(a$, i, 1) <> "-" the print a$;
NEXT
Even better, you can stick a _DELAY in the and get the universally-annoying teletype printing effect. Bonus points if you can find a corny sound effect to go with it.

Yep, I'd actually thought of doing that.  Perhaps I'll make it an option that can be turned ON/OFF, just as the whole text thing already is now.
Thanks for the input!