www.webdeveloper.com
Results 1 to 13 of 13

Thread: [RESOLVED] Javascript Music Player

  1. #1
    Join Date
    Jul 2009
    Posts
    48

    resolved [RESOLVED] Javascript Music Player

    Hello all, I am trying to make a script that speaks then plays music when its finished, below is my script. The trouble is its just a script file there is not html or anything meaning its opened with Windows Script Host.

    Code:
    function speak(txt)
    {
    	var objSpk = new ActiveXObject("SAPI.SpVoice");
    	objSpk.Speak(txt);
    }
    
    function music(src)
    {
    /* Unknown */
    }
    
    speak("test");

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    If this for local use only, you can get past the security prompt with .hta extension

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    	"http://www.w3.org/TR/html4/strict.dtd">
    <HTML>
    <HEAD><TITLE>Su11-44am32</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <STYLE type=text/CSS>
    
    
    </STYLE>
    <SCRIPT type="text/javascript">
    
    function speak(txt,musicFile){
    	var objSpk = new ActiveXObject("SAPI.SpVoice");
    	objSpk.Speak(txt);
    alert(musicFile)
    }
    
    </SCRIPT>
    <META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
    <BODY scroll="auto">
    <input type=button onclick="speak('testing 1 2 3 test, red green yellow blue','Done testing, can insert code to play music here');" value="test">
    
    
    </BODY></HTML>
    Choose you player and go for it. I need to find a new player again, my old one is having difficulty with all the subversive and covert updates by Windows.

  3. #3
    Join Date
    Oct 2006
    Posts
    939
    You can learn more about SpVoice here...
    http://msdn.microsoft.com/en-us/libr...02(VS.85).aspx
    Let me know if you find any examples written Jscript (similar to javascript)
    I'm lost with VBscript

  4. #4
    Join Date
    Jul 2009
    Posts
    48

    Thumbs down

    The problem is that its not a html document and is not linked to a html document. Its a javascript file that when double clicked on opens with WScript and plays the voice then the song. So yeah the first option doesn't really work for me, Im really sorry.

  5. #5
    Join Date
    Oct 2006
    Posts
    939
    There's not a whole lot to learn about Microsoft SpVoice. Rate and Volume is about all you need to adjust. I only have one voice on my machine, (Anna)

    One important item to know about is the numerical flag (argument) in Speak()

    Speak('speak this text',2)

    The default is 0 if left off and will lock the user out until the text has been spoken by the speech engine. There are a few of these numerical flags but they do things I'm not likely to use.

  6. #6
    Join Date
    Jul 2009
    Posts
    48
    thanks every1 for your suggestions but none of them actually play a musid file when the text has been spoken.

  7. #7
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    Enjoy:
    Code:
    //speak_and_play.js (JScript file)
    //Intended to be run as local executable (is JScript),
    //just double click on this file or right click and select 'Open'.
    //That is, provided that your .js files are set to open with Microsoft (R) Windows Based Script Host.
    //First, select the name of the proper executable from the 'executables' array below to pass to the 'music' function,
    //and provide your own file paths in the audioFiles array.
    function speak(txt){
        var objSpk = new ActiveXObject("SAPI.SpVoice");
        objSpk.Speak(txt);
    }
    function music(executableName, src){
        var WshShell = WScript.CreateObject("WScript.Shell");
        WshShell.Run(executableName +' '+ src);
    }
    speak("testing 1 2 3");
    var executables = [
        'CTCMSU', //Creative MediaSource 5 Player (CTCMSU.exe)
        'realplay', //RealPlayer (realplay.exe)
        'ShowTime', //Nero ShowTime (ShowTime.exe)
        'wmplayer' //Windows Media Player (wmplayer.exe)
    ];
    //note the file paths in the audioFiles array, the '\' character must be escaped: '\\'
    var audioFiles = [
        'C:\\testing\\BillCox-MyRoughRowdyWays.mp3',
        'C:\\testing\\HelenHumes-SongOfTheWanderer.mp3'
    ];
    //pass the name of one of the executables based upon what you have available on your system
    music(executables[3], audioFiles[0]);
    WScript.Sleep(30000); //30,000 milliseconds (30 seconds) delay, then we'll interrupt and load a different file:
    music(executables[3], audioFiles[1]);

  8. #8
    Join Date
    Jul 2009
    Posts
    48
    That one is really close but i need it to play without opening a dialog (e.g. WMP).

  9. #9
    Join Date
    Oct 2006
    Posts
    939
    Ok, I finally figured out how to know when the speech engine is done speaking and can fire an event after that. You might have a long introduction and, as I stated previously, a numerical flag must be used as an argument in speak() else the application virtually freezes giving the user fits as if the machine is crashing.

    So, what do you want the thing to say and can you point to a url, a .wav file you want to play?

  10. #10
    Join Date
    Jul 2009
    Posts
    48
    ok the .wav file i want it to play after speaking is at C:\Support018548\Support.wav.

  11. #11
    Join Date
    Jul 2009
    Posts
    48
    Oh i also want it to say Hello, Welcome to ***** Support, Please wait until someone is ready.

  12. #12
    Join Date
    Oct 2006
    Posts
    939
    Ok, since its all Windows, I loaded it up with Microsoft proprietary goodness.
    Change the extension to .html and get the security alert or if you are ready to start
    editing the code to suit you, change the extension to .hta
    Attached Files Attached Files

  13. #13
    Join Date
    Jul 2009
    Posts
    48
    Thankyou,it orks and i guess its the best i can do, oh well thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles