|
qq43142691
中级用户
  
积分 327
发帖 152
注册 2007-5-4
状态 离线
|
『楼 主』:
怎么用批处理播放声音文件啊百度都搜不到
使用 LLM 解释/回答一下
就是用命令调用声音文件.
或者VBS也可以...谁能告诉我啊.
Just use commands to call sound files. Or VBS can also be used... Who can tell me?
|
|
2007-6-16 12:28 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
|
2007-6-16 13:18 |
|
|
yjq635
初级用户
 
积分 109
发帖 42
注册 2007-5-12
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
这个是我以前找到的,具体哪个网站忘了,经测试是可以的!
如何在脚本播放一个声音?
问:
嗨,Scripting Guy!我有一个脚本可通过弹出消息框来警告用户发生了问题。有没有办法在弹出消息框的同时播放声音呢?
-- TL
答:
嗨,TL。你们这么做是故意的,不是吗?你们就爱问一些没有明确答案的问题。这次也是这样:您可以搜遍 VBScript 和 WSH 文档,但是您无法找到任何方法可让您通过脚本直接播放声音,即便只是“吱吱”声也办不到。或者,在这种情况下可能是“嘀嘀”声。
因此,必须调用另一个实用程序,以便播放声音。要是声音文件采用 .WAV 格式,最好使用 Windows 录音机。对于这一点,至少有两个理由。首先,录音机较为小巧,可以非常快地进行加载;Media Player 要强大得多,但是对于只是播放“嘀嘀”声,太大材小用了。其次,通过传递适当的命令行参数,可以隐式运行录音机;因此,您(或用户)将听到声音,但不会在屏幕上看到录音机。
以下脚本可以播放 Notify.wav(在 Windows\Media 文件夹下找到的一个标准的操作系统声音文件):
strSoundFile = "C:\Windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
该脚本的前两行非常简单。在第一行中,我们将该文件路径指派给了 strSoundFile 变量;在第二行中,我们创建了 Wscript Shell 对象(将用于实际运行录音机的对象)的一个实例。
第三行稍微麻烦一点。为了从命令提示符运行录音机,需要键入该命令:
sndrec32 /play /close "C:\Windows\Media\Notify.wav"
前两个命令行参数告诉录音机播放该文件,然后自动终止;当然,第三个参数就是所要播放的文件的名称。在该例中,不需要对文件路径加双引号;只有当路径名中含有空格时,才需要加引号。我们预先加了引号,以便为您提供模板,供您在播放路径名中确实含有空格的声音文件时使用。因此:
sndrec32 /play /close "C:\Windows\Media\Windows XP Error.wav"
为了对该文件路径加双引号,我们使用了 Chr(34) 命令(可在字符串中插入双引号)。因此,这行代码将 sndrec32 /play /close、前双引号 (“) 文件 C:\Windows\Media\Notify.wav 以及后双引号 (”) 串在了一起:
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
最后,在第四行中使用了 Run 方法,传递刚才构建的命令字符串。参数 0 可以让录音机在隐藏窗口中运行;参数 True 告诉该脚本等到声音播放结束后,再重新进行播放。
那么,至于在弹出消息框的同时播放声音,您会发现这几乎不可能;这是因为,录音机需要一两秒的时间来加载并开始播放。最好做两件事。首先,在调用录音机时,使用参数 False;这将告诉该脚本启动录音机并无需等到声音播放结束后就可以继续播放。
其次,使用 Wscript.Sleep 命令将脚本暂停大约一秒钟;从而让录音机有时间进行加载,幸运的话,大约会在弹出消息框时开始播放该声音。能否恰好在弹出消息框的同时播放声音呢?一般不会。但至少可以接近于同时进行。
这里有一个示例脚本也可以大约在弹出消息框的同时播放声音:
strSoundFile = "C:\windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, False
Wscript.Sleep 1000
Msgbox "A problem has occurred."
责任编辑:孤红雪
This is something I found before, and I forgot which website it was from. It has been tested to be functional!
How to play a sound in a script?
Q:
Hi, Scripting Guy! I have a script that alerts the user of a problem by popping up a message box. Is there a way to play a sound at the same time as the message box pops up?
-- TL
A:
Hi, TL. You guys are doing this on purpose, aren't you? You just love asking questions with no clear answers. This time is the same: You can search through VBScript and WSH documentation, but you won't find any way to directly play a sound through the script, not even a "beep" sound. Or, in this case, maybe a "beep-beep" sound.
Therefore, you must call another utility to play the sound. If the sound file is in .WAV format, it's best to use Windows Sound Recorder. There are at least two reasons for this. First, Sound Recorder is relatively small and can be loaded very quickly; Media Player is much more powerful, but it's overkill for just playing a "beep-beep" sound. Second, you can run Sound Recorder implicitly by passing appropriate command-line parameters; so you (or the user) will hear the sound but won't see Sound Recorder on the screen.
The following script can play Notify.wav (a standard operating system sound file found in the Windows\Media folder):
strSoundFile = "C:\Windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
The first two lines of this script are very simple. In the first line, we assign the file path to the strSoundFile variable; in the second line, we create an instance of the Wscript Shell object (the object that will be used to actually run Sound Recorder).
The third line is a bit more complicated. To run Sound Recorder from the command prompt, you need to type this command:
sndrec32 /play /close "C:\Windows\Media\Notify.wav"
The first two command-line parameters tell Sound Recorder to play the file and then terminate automatically; of course, the third parameter is the name of the file to play. In this example, you don't need to put double quotes around the file path; you only need to put quotes when the path name contains spaces. We prefixed with quotes to provide you with a template for when you play sound files whose path names do contain spaces. So:
sndrec32 /play /close "C:\Windows\Media\Windows XP Error.wav"
To put double quotes around this file path, we use the Chr(34) command (which inserts a double quote in the string). So this line concatenates sndrec32 /play /close, the opening double quote ("), the file C:\Windows\Media\Notify.wav, and the closing double quote ("):
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
Finally, in the fourth line, the Run method is used, passing the command string that was just built. Parameter 0 makes Sound Recorder run in a hidden window; parameter True tells the script to wait until the sound finishes playing before continuing.
As for playing a sound at the same time as the message box pops up, you'll find that it's almost impossible; this is because Sound Recorder takes a second or two to load and start playing. It's best to do two things. First, when calling Sound Recorder, use parameter False; this will tell the script to start Sound Recorder and not wait until the sound finishes playing to continue.
Second, use the Wscript.Sleep command to pause the script for about one second; this gives Sound Recorder time to load, and hopefully, the sound will start playing around the time the message box pops up. Can it play the sound exactly at the same time as the message box pops up? Usually not. But at least it can be close to simultaneous.
Here's an example script that can also play the sound around the time the message box pops up:
strSoundFile = "C:\windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, False
Wscript.Sleep 1000
Msgbox "A problem has occurred."
Responsible Editor: Gu Hongxue
|
|
2007-6-16 16:48 |
|
|
eech
高级用户
   
积分 906
发帖 346
注册 2006-7-10
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我机子改成100毫秒正好同步,嘿嘿
My machine is just in sync at 100 milliseconds, heh heh
|
|
2007-6-17 17:25 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
用bat的话可以尝试直接start 声音文件,会自动用相应的播放器来播放。
用vbs的话则有多种方案:
一,使用WMPlayer.OCX
1.1使用URL:
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.URL = "D:\音乐\歌曲\王心凌\彩虹的微笑.mp3"
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
1.2使用Playlist:
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.currentPlaylist.appendItem oPlayer.newMedia("D:\音乐\歌曲\王心凌\彩虹的微笑.mp3")
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
二.使用SAPI.SpFileStream
Set oVoice = CreateObject("SAPI.SpVoice")
Set oFile = CreateObject("SAPI.SpFileStream.1")
oFile.Open "c:\Windows\Media\Ding.wav"
oVoice.Speakstream oFile,1 '注意这里的参数1加与不加的效果
Wscript.Echo "出错了..."
Set oVoice = Nothing
Set oFile = Nothing
注意:此方案只能播放WAV格式的声音。
另外,使用某些常用第三方软件提供的可被VBS调用的组件也可以实现。
With bat, you can try to directly start the sound file, and it will automatically play with the corresponding player.
With vbs, there are multiple solutions:
I. Using WMPlayer.OCX
1.1 Using URL:
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.URL = "D:\Music\Songs\Cyndi Wang\Rainbow Smile.mp3"
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
1.2 Using Playlist:
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.currentPlaylist.appendItem oPlayer.newMedia("D:\Music\Songs\Cyndi Wang\Rainbow Smile.mp3")
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
II. Using SAPI.SpFileStream
Set oVoice = CreateObject("SAPI.SpVoice")
Set oFile = CreateObject("SAPI.SpFileStream.1")
oFile.Open "c:\Windows\Media\Ding.wav"
oVoice.Speakstream oFile,1 'Note that the effect of adding or not adding the parameter 1 here
Wscript.Echo "An error occurred..."
Set oVoice = Nothing
Set oFile = Nothing
Note: This solution can only play WAV - format sounds.
In addition, using some commonly - used third - party software - provided components that can be called by VBS can also be implemented.
|
|
2007-6-17 18:17 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
//用bat的话可以尝试直接start 声音文件,会自动用相应的播放器来播放。
我在XP SP2下用start试了一下,不行。只是弹出一个msdos窗口,并没有播放声音。
3742668斑竹,何解啊?
@echo off
start "C:\WINDOWS\Media\Windows XP Startup.wav"
//Using bat, you can try to directly start the sound file, and it will automatically use the corresponding player to play.
I tried start under XP SP2, but it didn't work. Only a msdos window popped up, and the sound wasn't played.
Bamboo administrator 3742668, what's the reason?
@echo off
start "C:\WINDOWS\Media\Windows XP Startup.wav"
|
|
2007-6-17 21:25 |
|
|
Vampire
初级用户
 
积分 176
发帖 78
注册 2007-4-15
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
可能是关联有问题,你查看看关联:cmd /k for /f "tokens=2 delims==" %i in ('assoc .wav') do ftype %i
可能是关联有问题,你查看看关联:cmd /k for /f "tokens=2 delims== %i in ('assoc .wav') do ftype %i
It may be a problem with the association. You can check the association: cmd /k for /f "tokens=2 delims== %i in ('assoc .wav') do ftype %i
|
|
2007-6-18 00:00 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by HAT at 2007-6-17 21:25:
//用bat的话可以尝试直接start 声音文件,会自动用相应的播放器来播放。
我在XP SP2下用start试了一下,不行。只是弹出一个msdos窗口,并没有播放声音 ...
@echo off
start "" "C:\WINDOWS\Media\Windows XP Startup.wav"
Originally posted by HAT at 2007-6-17 21:25:
//You can try to directly start the sound file with bat, which will automatically play it with the corresponding player.
I tried start under XP SP2 and it didn't work. Only a msdos window popped up, and no sound was played...
@echo off
start "" "C:\WINDOWS\Media\Windows XP Startup.wav"
|
|
2007-6-18 01:28 |
|
|
qq43142691
中级用户
  
积分 327
发帖 152
注册 2007-5-4
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
set mp3=c:\opera.mp3
copy /y "C:\Program Files\Windows Media Player\wmplayer.exe" %windir%\system32\
start /min wmplayer "%mp3%"
set mp3=c:\opera.mp3
copy /y "C:\Program Files\Windows Media Player\wmplayer.exe" %windir%\system32\
start /min wmplayer "%mp3%"
|
|
2007-7-31 05:40 |
|
|
vive666888
初级用户
 
积分 34
发帖 17
注册 2007-6-29 来自 介休
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
哈,学习了,谢谢各位高人
Hehe, learned something, thanks to all the experts
|
|
2007-7-31 16:16 |
|
|
qq43142691
中级用户
  
积分 327
发帖 152
注册 2007-5-4
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.URL = "d:\有一种爱叫做放手.mp3"
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
Set oPlayer = CreateObject("WMPlayer.OCX")
oPlayer.URL = "d:\有一种爱叫做放手.mp3"
oPlayer.controls.play
Do
WScript.Sleep 100
Loop Until oPlayer.openState <> 12
WScript.Sleep oPlayer.currentMedia.duration * 1000
|
|
2007-8-1 06:28 |
|
|
ngdao
初级用户
 
积分 20
发帖 11
注册 2007-8-2
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
用mplayer可以在DOS下播放音乐
mplayer.exe "C:\Documents and Settings\Administrator\My Documents\My Music\朋友.mp3"
我的网盘中有这个软件
http//ngd.ys168.com
You can play music under DOS with mplayer
mplayer.exe "C:\Documents and Settings\Administrator\My Documents\My Music\Friend.mp3"
I have this software in my cloud disk
http//ngd.ys168.com
|
|
2007-8-2 22:57 |
|
|
tophu0041463
初级用户
  少帅
积分 42
发帖 24
注册 2009-12-17 来自 深圳
状态 离线
|
|
2010-1-5 07:45 |
|