Results 1 to 16 of 16

Thread: Playing a sound using PERL in WIn98

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55

    Playing a sound using PERL in WIn98

    A friend wrote a script that works on XP and 2000 but not on my 98 machine. The script checks a log file and when certain text is matched it should paly a sound file but it doesn't work on WIn 98.

    here's the script:


    Code:
    use strict;
    
    #
    #   Parameters
    #
    
    my $ChatLog = "c:\\mythic\\camelot\\chat.log";
    
    my $TerminatorString = "--END--";
    
    my @ParserArray = (
        "c:\\windows\\media\\tada.wav",         "You successfully make",
        "c:\\windows\\media\\ding.wav",         "You fail to make",
        "c:\\windows\\media\\tada.wav",         "this will do nicely",
        $TerminatorString,  $TerminatorString );
    
    #
    #   External stuff
    #
    
    use Win32::Sound;
    
    #
    #   Set the sound volume.
    #
    
    Win32::Sound::Volume( '100%' );
    
    #
    #   Recreate the chat log file. We don't want to read the chat log
    #   from the last session when the script starts up.
    #
    
    system( "copy $ChatLog $ChatLog.old" );
    open( CHATLOG, ">$ChatLog" )
        || die( "Unable to clear chat log file: $ChatLog" );
    close( CHATLOG );
    
    #
    #   Open a read handle to DAoC's chat log.
    #
    
    open( CHATLOG, $ChatLog )
        || die( "Unable to open chat log file: $ChatLog" );
    
    #
    #   Read loop.
    #
    
    while ( 1 )
    {
        while ( <CHATLOG> )
        {
            print( $_ );
            
            #
            #   Match the input string against all parser array strings.
            #
            
            my $i = 1;
            while ( !( $ParserArray[ $i ] =~ /$TerminatorString/ ) )
            {
                if ( /$ParserArray[ $i ]/ )
                {
                    print( "MATCH with \"$ParserArray[ $i ]\"\n" );
                    
                    #
                    #   Play the sound associated with this string.
                    #
                    
                    my $WavFile = $ParserArray[ $i - 1 ];
                    print( "PLAY $WavFile\n" );
                    Win32::Sound::Play( $WavFile );
                }
    
                $i = $i + 2;
            }
        }
        
        #
        #   
        
        print( "Sleeping to wait for more chat.log input...\n" );
        sleep( 1 );
    }
    
    #
    #   Cleanup
    #
    
    close( CHATLOG );
    If anyone has any suggestiosn on how to make this work, please let mek now ASAP!

    Thanks,
    --Kel
    Last edited by kelemvor; Oct 30th, 2001 at 02:50 PM.

  2. #2
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340

    well...

    what server are you using?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  3. #3

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55
    What do you mean by What Server am I using? I d/l'd Perl and am running WIndows 98 and it's reading a text file. Not sure what you're asking for.
    --Kel

  4. #4
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    you have to run perl off of a server, at least for web use as far as i know. what server you are running will affect the code. Are you running IIS, PWS, Apache, etc?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  5. #5
    scoutt
    Guest
    perl can' t run without a server (apache, or IIS or Xtami). it will but don't blink as it happens so fast.

  6. #6

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55
    Well, I'm not running a server. I downloaded Perl from here:
    http://downloads.activestate.com/Act...lti-thread.msi

    and when I run the script, a dos box opens up and scrolls text so it is running it seems, it's just not playing sounds at all.

    Unless I'm missing something.

    I have no experience whatsoever with Perl at all but lots of people use it to make simple macros and such I'm told, which is all this is doing really.

    --Mike

  7. #7
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Why the heck do you guys think you need a server to run Perl? It's just another programming language. Heck, you could even write your web server in Perl if you wanted too.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  8. #8
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    This simple script from the docu. works for me under windows 2000:

    Code:
    use Win32::Sound;
    
    
        # Create the object
        $WAV = new Win32::Sound::WaveOut(44100, 8, 2);
    
        $data = ""; 
        $counter = 0;
        $increment = 440/44100;
    
        # Generate 44100 samples ( = 1 second)
        for $i (1..44100) {
            # Calculate the pitch 
            # (range 0..255 for 8 bits)
            $v = sin($counter/2*3.14) * 128 + 128;
            # "pack" it twice for left and right
            $data .= pack("cc", $v, $v);
            $counter += $increment;
        }
    
    
        $WAV->Load($data);       # get it
        $WAV->Write();           # hear it
        1 until $WAV->Status();  # wait for completion
        $WAV->Save("sinus.wav"); # write to disk
        $WAV->Unload();          # drop it
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  9. #9

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55
    The origina script I posted DOES work under Windows 2000, but not under WINDOWS 98 which is what I'm trying to figure out why.
    --Mike

  10. #10
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Well, can you isolate which part of the script isn't working? Is it not playing sounds, and working otherwise? Does it not find some of the files - make sure the paths are correct.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  11. #11

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55
    As far as I know, it's just not playing sounds. When I run the script, the box appears and display the line reading:

    Sleeping to wait for more chat.log input...

    So it's at least opening the file and checking for updates. The file only updates while playing a game so I can't actually see the file whiel playing but I'm assuming the IF statements are finding the string match and it's just not playing sounds.

    Thanks for all the help so far,
    --Mike

  12. #12
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Well, make sure you can play the files thru something else (Media Player, etc) -- I've had .wav files get corrupt on me before.

    Then, trying writing a simple Perl app that does nothing but plays a sound file.

    Let me know what happens tomorrow.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  13. #13
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Originally posted by JoshT
    Why the heck do you guys think you need a server to run Perl? It's just another programming language. Heck, you could even write your web server in Perl if you wanted too.
    i know, i just kind of assumed since this was a web forum, he would be running it off the internet. Shows you shouldn't assume.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  14. #14
    scoutt
    Guest
    I know you don't need a server to run perl. I was going with sail and it is all his fault.. blame it on Sail, yeah that worthless piece of **** lol just kidding sail.

    all the perl programs I have used just runs the dos window and disappears. that was the only reason I suggested what I did.

  15. #15

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Milwaukee, WI
    Posts
    55
    Well, upon further investigation, it appears the script runs if you run it by itself, but when you run it and then open up the game it's written for on top, that Win 98 wont' let the script use the sound card if since the game is using it.

    Not sure if that's techincalyl correct, but that's all I can figure out. It looks like the script is OK, but it's an OS thing that wno't let the two programs play together.

    --Mike

  16. #16
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    That makes sense to me.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

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



Click Here to Expand Forum to Full Width