Turn On/Off SAPI during Game?

On the Menu bar, under Tools --> Options... --> checkbox "Speak all text (via SAPI)", you can turn a computer voice on/off. Is there a way to run a script to do this during the game? Would be a cool sound effect...

oh wow, quest can use the Speech-API too?! That's so cool! I don't know much of computer-system/microsoft stuff, but I found code to just access the Speech-API, to get your computer to 'talk', hehe.

(If you understand/know more about the Speech-API, I would love some help in learning more in how to use it and etc!)

I don't think the game itself even knows if that feature is being used or not.

(I tried to figure this out once before, but I didn't try very hard, so, I may be mistaken.)

I'm trying to make speak.js work, but speakWorker and importScripts don't seem to work correctly because they need to import files from the local drive, which I don't believe is going to happen unless I wrap all this in JS.eval() or come up with some funky ASLEvent which allows me to use GetFileURL...

I changed the script so speakWorker equaled the onmessage() function from the file from which the script was trying to read (speakWorker.js), but that threw an error about postMessage() being undefined, which is where I am currently stuck.

I added the script from speakWorker.js to speakClient.js, and that didn't seem to effect anything.

NOTE: I have all three JS files included as Javascript files in one test game, and I have a separate game with the files in the game's folder, which uses the HTML <script> method, but neither one works in the desktop player (at the moment) for me.



One problem (I think):

speakWorker = new Worker('speakWorker.js');

The other problem (I think):


If this could be modified to work, you could just enter JS.speak('Hello, Quest Forum!') (or whatever else you wanted to 'say').

Dirty tricks + speak.js + Lots of free time = http://textadventures.co.uk/games/view/bwilf7iehecgchbiixexwq/speaking-with-js

It doesn't really turn on SAPI, but it reads whatever I tell it to read in a similar voice.



Okay... This is extremely dirty.

I made an .html file:


<!DOCTYPE html>
<script src="speakClient.js"></script>

<div id="audio"></div>

speak("Greetings, Adventurer!  Welcome to the game!  You can enter HELP if you require assistance!"); 

I zipped it up along with speakClient.js, speakGenerator.js, and Worker.js, which I downloaded from the link to speak.js in the above post. Then, I submitted that zipped file as a game.

Then, I made this game:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Speaking with JS">
  <object name="room">
    <inherit name="editor_room" />
    <description type="script"><![CDATA[
      msg ("<iframe id='speakDiv' width='0' height='0' src='http://media.textadventures.co.uk/games/2wHZlJ6i-kWuIdZek09HfA/index.html'></iframe>")
      JS.eval ("$('#speakDiv').hide();")
      msg ("You should hear the voice in a few moments.  (It won't read the text from the screen.  ...but, it might later, after a little work.)")
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />

Now, I must learn how to modify those JS scripts so all required functions are accessible without importing files. That way, it won't be dependent upon the uploaded HTML 'game'.

(Anyone suggestions?)

I shall return.

You can open up Audacity (which can be found here) and switch Windows WASAPI to Speakers to record whatever your PC is putting out.



So, I hit "RECORD" on that, then opened my web page. Now, I have the audio file of the text being read by speak.js, which I can include in the game and bypass the extra web page.

I'm still working on getting the JS to work in the game.

I don't believe the problem is insurmountable.

Is this sort of answering the question, or have I gotten too far off track? (It's cool with me either way. I'm just making sure I'm not cluttering up the thread with things which aren't helpful. (Hehehe.))

Are you wanting a computer voice to read exactly what you tell it to read (be it room descriptions or whatever else you decide)? Or are you wanting to actually switch SAPI on and off during play?

Thank you again, KV, for all your experimenting. It's hard for me to reply as I'm just trying to understand what you're doing. I didn't need to actually turn SAPI on/off; I just wanted a computer voice to speak the text that I wanted.

Oh, okay. We're rockin' and rollin', then.

..and it's no problem, really. I like to help (and to learn), so it's all gravy!

I'm trying to understand what I'm doing, too! (Ha-ha! )

  • speak.js is a thing someone else created, which is available from GitHub

  • We can include JS files in Quest, just like libraries, but things don't quite work right sometimes.

    • This is one of those times, of course.
  • If the speak.js functions all worked properly, we could just put JS.speak("Welcome to the game, Adventurer!"), and the SAPI voice would say that.

  • I couldn't get it to work inside a Quest game, so I opened up Notepad++ and created an .html file (posted above), which includes the .js files required for speak.js (the ones that Quest doesn't like). This HTML page calls speak('Greetings, Adventurer! Blah, blah, blah...'). When the page loads, the SAPI voice reads the dialog.

  • I named that HTML file index.html, then I zipped it up with the three required .js files from speak.js.

  • I uploaded that zipped file to this site as a game. (It's only a web page that 'reads' my dialog in the SAPI voice.)

  • I created an actual Quest game, with an iframe element, the source of which is the HTML game's URL, which I just got when I submitted that zip file.

  • I used JS in Quest to hide the iframe element, but the sound still plays.

Later, I decided to bypass the extra "game" with the audio to keep from depending upon an external web page.

  • I opened Audacity and switched the recording device from the system's microphone to the system's speakers.

  • I pressed RECORD in Audacity and opened up the HTML page, which read the text aloud in the SAPI voice.

  • I flipped back to Audacity and exported the audio file as an .ogg, named sapi_dialog1.ogg.

  • Now, I can just play this file instead of using an iframe, and there's no need to link to an external webpage.


  • I haven't uploaded the version that uses the .ogg. What's online still has the iframe which loads an external page for the sound.

  • I still plan to make the JS work inside of Quest, so we can just enter speak("BWAHAHAHAHA! The princess is in another castle!").

  • What I think the problem is:

    • Two of the JS files import each other (or something). One of them does it as a Worker (which is a process I'm not familiar with).
    • I assume this is just like including the JS file in the script in an HTML file, but I don't know how to just skip the importing and set the variable to the contents of the file it's importing in JS.

Usually typing things out forces me to get a better grasp on what it is I'm doing, but not this time. (Sorry. Hehehe.)

This is a great synopsis of what you just did, and very understandable to a layperson such as myself. Thanks for your efforts. I guess my initial question was if there was an "easy" way to have the computer voice in a game, the answer being "no" (haha).

This topic is now closed. Topics are closed after 60 days of inactivity.