Play a sound (.wav) file, without opening an application

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stephjo
Posts: 12
Joined: 03 Feb 2014 02:39

Play a sound (.wav) file, without opening an application

#1 Post by stephjo » 10 Nov 2019 16:51

Hello DOS folks,

I was wondering if there's a way in DOS (or Windows 7 in general) to play a media file without invoking a software.

Here's what I am looking for ... at the end of a batch file or a C++ program that takes many minutes to complete, I'd like to "beep" by playing the file "C:\Windows\Media\tada.wav".

I would like to use something like one of these commands, but don't want Windows to open whatever .WAV application. It's one more window to close.

start "" "C:\Windows\Media\tada.wav"
"C:\Windows\Media\tada.wav"

Just like with any other Windows notification (new mail or Windows error), I'd like my computer to just play the file without opening any application.

How could I achieve this?

Thank you,
--Steph

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Play a sound (.wav) file, without opening an application

#2 Post by aGerman » 10 Nov 2019 17:38

There has to be an application involved which is able to process and play your sound file. But the Windows Media Player provides an interface without window using ActiveX. It's not accessible with Batch directly. But you can use hybrid scripts such as npocmaka's mediarunner.bat.
https://github.com/npocmaka/batch.scrip ... runner.bat

Steffen

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Play a sound (.wav) file, without opening an application

#3 Post by miskox » 11 Nov 2019 04:29

You could ECHO BEL (0x07) (or many of them).

Saso

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Play a sound (.wav) file, without opening an application

#4 Post by misol101 » 11 Nov 2019 19:39

Another predictable answer, but CmdWiz has the "playsound" operation. ( viewtopic.php?t=7402, see chapter 10).

You wrote that you don't want to invoke software, but the main thing seems to be avoiding a window opening ? Cmdwiz will not do that when run from a batch script.

Code: Select all

:: Play and wait for sound to finish
cmdwiz playsound C:\Windows\Media\tada.wav

:: Play without waiting
start /B cmdwiz playsound C:\Windows\Media\tada.wav

Lowsun
Posts: 29
Joined: 14 Apr 2019 17:22

Re: Play a sound (.wav) file, without opening an application

#5 Post by Lowsun » 12 Nov 2019 14:03

If you're looking for anything other than a standard beep, you can embed VBScript inside your batch file. It uses an embedding method from dbenham over here https://stackoverflow.com/questions/907 ... ut-using-a. At the top of the script add

Code: Select all

<!-- : Begin batch script
And at the bottom add

Code: Select all

----- Begin wsf script --->
<package>
  <job id="Sound">
    <script language="VBScript">
      Set Sound = CreateObject("WMPlayer.OCX.7")
      Sound.URL = WScript.Arguments.Item(0)
      Sound.Controls.play
      do while Sound.currentmedia.duration = 0
      Wscript.sleep 100
      loop
      Wscript.sleep (int(Sound.currentmedia.duration)+1)*1000
    </script>
  </job>
  <job id="Music">
    <script language="VBScript">
      Set Sound = CreateObject("WMPlayer.OCX.7")
      Sound.URL = WScript.Arguments.Item(0)
      Sound.settings.volume = 100
      Sound.settings.setMode "loop", True
      Sound.Controls.play
      While Sound.playState <> 1
      WScript.Sleep 100
      Wend
    </script>
  </job>
</package>
It contains 2 types of playing : repeating the mp3 after it is done over and over (Music) and just playing it once (Sound). You can make a macro called "music" for a handy way to access both.

Code: Select all

SET "music=START /B CSCRIPT //NOLOGO "%~f0?.wsf" //JOB:t s.mp3 >NUL"
Ie, if you want your tada.mp3 to play once, you can do:

Code: Select all

%music:t s=Sound tada%

Post Reply