2

Here is a new challenge, I want to make windows 10 command prompt or PowerShell window to play a tiny very short 'tick' sound like they do in the movies, everytime there is a new line printed on the command window, whether it is directly in the command or it is in let's say >>> python environment, I want it to tick, every time there is a new line printed, no matter what application is being run inside the cmd.

The beauty of it all is that you can easily do this in Linux terminals. Any ideas how to do it for Widnows 10?

Thank you folks

3
  • 1
    Just do a search for 'PowerShell play sounds' or 'cmd play sounds', and you'll get a list for that sort of thing.
    – postanote
    Jan 19, 2019 at 19:30
  • Thank you @postanote . I have already searched for that stuff, nothing was found that would be useful and practical, which is why I am here asking this question.
    – JackBixuis
    Jan 19, 2019 at 19:34
  • I love you OP I've been thinking same thing for ages. Feb 8 at 13:14

1 Answer 1

4

Playing a sound in PS is as simple as doing this...

# this
"`a" 

# or this basic tone
[console]::beep(1000, 500)

Change the value of the first number to alter the pitch (anything lower than 190 or higher than 8500 can’t be heard), and change the value of the second number to alter the duration:

# Or this
[System.Media.SystemSounds]::Beep.Play()

Then tie that to you output code. For external exe in PS you have to code to retrieve output from that, using PS redirection.

Use whatever tool you choose to create the sound you'd want to play. Of course that has to be on all the systems you plan to run your code.

1..3 | %{
    'Play a sound'
    [console]::beep(1000, 500)
}

Update for OP

No worries.

As for (1) - you should just need to add the sound line before or after the expected text output, as in that shown loop example.
As for (2) it's no where near as flexible. You are limited to using CRTL+G in a .bat/.cmd file and calling that before or after your expected output line.

Yet, again, you'd have to code to trap all the output you are after. Playing wav files, mean calling a media player in your code especially for cmd.exe.

# PowerShell playing a wav file
$PlayWav=New-Object System.Media.SoundPlayer
$PlayWav.SoundLocation='C:\Foo\Soundfile.wav'
$PlayWav.playsync()

# CMD playing a wav file
start 'C:\Foo\Soundfile.wav'

Here's the real issue with play .wav files, or anything outside of the normal console beeps, the media player will be called each time and have to display to play the file and have to be dismissed. Not a very automated thing..

So, IMHO for what you are after stick with the native console sounds.

3
  • This was superb helped more than you could imagine, but two questions remain: 1- Can I use this to play a tiny wav file, for every line of code that is printed on the output, and 2- How can I do this on the cmd.exe as well?
    – JackBixuis
    Jan 19, 2019 at 21:57
  • See my update for you.
    – postanote
    Jan 20, 2019 at 4:17
  • Thank you. I was mostly looking for an automated way. Like the shell or cmd playing a tiny tune all by itself, and on every output line, not only on a designated place. More like an audio template for cmd or PS, that every time there is an activity of the window of terminal, it would play a tiny little bleep. Kind of like what command prompts sound like in Hollywood movies.
    – JackBixuis
    Jan 21, 2019 at 1:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .