in reply to Playing wav files
If you're wondering why this script creates a TEMP folder, it's because Windows 8 and higher will give an Access Denied error if you try to create a file in the root folder. So, we can't create a temp file like C:\TEMP.TXT or anything like that. Windows XP would handle it all right, but Windows 10 requires you to have admin privilege for that. But you don't need admin privilege to create a folder and put a file within that folder.)
#!/usr/bin/perl -w use strict; use warnings; SAY("Hello World!!!"); exit; # Usage: STATUS = SAY(TEXT, VOLUME) - Reads a text in computer voice o +n Windows computers (tested on Windows XP) Returns 1 if something was + read or 0 if nothing was read sub SAY { @_ or return 0; my $TEXT = shift; defined $TEXT or return 0; length($TEXT) or return 0; my $VOLUME = @_ ? shift : 100; defined $VOLUME or $VOLUME = 100; length($VOLUME) or $VOLUME = 100; $TEXT =~ tr|\"| |; # Remove all quotes print "\n\n$TEXT\n\n"; # For those who are deaf, it's important to a +lso print the same message. my $TEMP_VBS_FILE = 'C:\\TEMP\\SAY.VBS'; my $TEMPDIR = substr($TEMP_VBS_FILE, 0, rindex($TEMP_VBS_FILE, "\\") + + 1); my $VB_SCRIPT = "IF Wscript.Arguments.length > 1 THEN\nSET VOICE = C +reateObject(\"SAPI.SpVoice\")\nVOICE.Volume = Wscript.Arguments(0)\nV +OICE.Speak Wscript.Arguments(1)\nELSE\nWscript.echo \"Usage: say.vbs +<VOLUME> <TEXT>\"\nEND IF\n"; unless (-f $TEMP_VBS_FILE && -s $TEMP_VBS_FILE == length($VB_SCRIPT) +) { mkdir $TEMPDIR; open(SCRIPTFILE, "> $TEMP_VBS_FILE") or return 0; print SCRIPTFILE $VB_SCRIPT; close SCRIPTFILE; } `$TEMP_VBS_FILE $VOLUME \"$TEXT\"`; #unlink $TEMP_VBS_FILE; #rmdir $TEMPDIR; return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Playing wav files
by Your Mother (Archbishop) on Feb 08, 2019 at 18:20 UTC | |
by bliako (Abbot) on Feb 09, 2019 at 09:40 UTC | |
|
Re^2: Playing wav files
by IB2017 (Pilgrim) on Feb 08, 2019 at 18:36 UTC | |
by harangzsolt33 (Deacon) on Feb 09, 2019 at 02:02 UTC |