Also related: If you just want your computer to read something to you out loud, you can do that too. This code works on Windows XP and higher. This code creates a VBScript file on the hard drive and executes it, so it's not the most ideal solution, but the job gets done! Lol

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; }

In reply to Re: Playing wav files by harangzsolt33
in thread Playing wav files by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.