|
-
Oct 29th, 2001, 05:38 PM
#1
Thread Starter
Member
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.
-
Oct 29th, 2001, 06:19 PM
#2
PowerPoster
well...
what server are you using?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Oct 29th, 2001, 06:24 PM
#3
Thread Starter
Member
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
-
Oct 29th, 2001, 06:26 PM
#4
PowerPoster
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
-
Oct 29th, 2001, 06:38 PM
#5
perl can' t run without a server (apache, or IIS or Xtami). it will but don't blink as it happens so fast.
-
Oct 29th, 2001, 10:58 PM
#6
Thread Starter
Member
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
-
Oct 30th, 2001, 12:26 PM
#7
Black Cat
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.
-
Oct 30th, 2001, 12:31 PM
#8
Black Cat
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.
-
Oct 30th, 2001, 01:53 PM
#9
Thread Starter
Member
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
-
Oct 30th, 2001, 02:23 PM
#10
Black Cat
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.
-
Oct 30th, 2001, 03:06 PM
#11
Thread Starter
Member
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
-
Oct 30th, 2001, 03:59 PM
#12
Black Cat
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.
-
Oct 30th, 2001, 04:31 PM
#13
PowerPoster
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
-
Oct 30th, 2001, 09:30 PM
#14
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.
-
Oct 31st, 2001, 04:50 PM
#15
Thread Starter
Member
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
-
Nov 1st, 2001, 07:44 AM
#16
Black Cat
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|