473,698 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

raw audio in windows

Hi. I've written a small python script that was primarily meant for
use in a unix-compatible environment. It writes a bunch of raw audio
to a file and then sends the file to /dev/audio and the system plays
the audio. Very simple.

Is there a simple way I could edit the script (which just uses the
system call to do this) to run under windows?

This is the code that would have to change:
os.system("cat audioBuf /dev/audio")

Sep 1 '06 #1
6 2335
On 31 Aug 2006 21:34:13 -0700, "Putty" <ja*******@gmai l.comwrote:
>Hi. I've written a small python script that was primarily meant for
use in a unix-compatible environment. It writes a bunch of raw audio
to a file and then sends the file to /dev/audio and the system plays
the audio. Very simple.

Is there a simple way I could edit the script (which just uses the
system call to do this) to run under windows?

This is the code that would have to change:
os.system("c at audioBuf /dev/audio")

hey, that sounds like some stuff i've been working on...
is there any possibility that you could send me that script so I could
take a look at it and learn?
i'm new to python and programming in general. i'm working on some
algorithmic composition stuff and also trying to write some synths....
here's my email...
da********@yaho o.com
Sep 1 '06 #2
Putty wrote:
Hi. I've written a small python script that was primarily meant for
use in a unix-compatible environment. It writes a bunch of raw audio
to a file and then sends the file to /dev/audio and the system plays
the audio. Very simple.

Is there a simple way I could edit the script (which just uses the
system call to do this) to run under windows?

This is the code that would have to change:
os.system("cat audioBuf /dev/audio")
Not really. You'll have to convert it to .wav and then pass it to a
helper app.

<http://www.microsoft.c om/technet/scriptcenter/resources/qanda/nov04/hey1103.mspx>

--
Ben Sizer

Sep 1 '06 #3
Ben Sizer wrote:
Not really. You'll have to convert it to .wav and then pass it to a
helper app.

<http://www.microsoft.c om/technet/scriptcenter/resources/qanda/nov04/hey1103.mspx>
>>import winsound
help(winsound )
Help on module winsound:

NAME
winsound

FILE
c:\python24\dll s\winsound.pyd

DESCRIPTION
PlaySound(sound , flags) - play a sound
SND_FILENAME - sound is a wav file name
SND_ALIAS - sound is a registry sound association name
SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC
SND_MEMORY - sound is a memory image of a wav file
SND_PURGE - stop all instances of the specified sound
SND_ASYNC - PlaySound returns immediately
SND_NODEFAULT - Do not play a default beep if the sound can not be found
SND_NOSTOP - Do not interrupt any sounds currently playing
SND_NOWAIT - Return immediately if the sound driver is busy

Beep(frequency, duration) - Make a beep through the PC speaker.

FUNCTIONS
Beep(...)
Beep(frequency, duration) - a wrapper around the Windows Beep API

The frequency argument specifies frequency, in hertz, of the sound.
This parameter must be in the range 37 through 32,767.
The duration argument specifies the number of milliseconds.
On WinNT and 2000, the platform Beep API is used directly. Else funky
code doing direct port manipulation is used; it's unknown whether that
will work on all systems.

MessageBeep(... )
MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK.

PlaySound(...)
PlaySound(sound , flags) - a wrapper around the Windows PlaySound API

The sound argument can be a filename, data, or None.
For flag values, ored together, see module documentation.

DATA
MB_ICONASTERISK = 64L
MB_ICONEXCLAMAT ION = 48L
MB_ICONHAND = 16L
MB_ICONQUESTION = 32L
MB_OK = 0L
SND_ALIAS = 65536L
SND_APPLICATION = 128L
SND_ASYNC = 1L
SND_FILENAME = 131072L
SND_LOOP = 8L
SND_MEMORY = 4L
SND_NODEFAULT = 2L
SND_NOSTOP = 16L
SND_NOWAIT = 8192L
SND_PURGE = 64L

</F>

Sep 1 '06 #4
Jay
I'm afraid I can't do that. Don't take it personally. I would send it
to you, but at this time, I'm developing this app with a friend and I
don't know his feelings about the program's distribution or licensing.
I can't send it around until I speak to him about it.

Sorry.
spiffy wrote:
On 31 Aug 2006 21:34:13 -0700, "Putty" <ja*******@gmai l.comwrote:
Hi. I've written a small python script that was primarily meant for
use in a unix-compatible environment. It writes a bunch of raw audio
to a file and then sends the file to /dev/audio and the system plays
the audio. Very simple.

Is there a simple way I could edit the script (which just uses the
system call to do this) to run under windows?

This is the code that would have to change:
os.system("cat audioBuf /dev/audio")


hey, that sounds like some stuff i've been working on...
is there any possibility that you could send me that script so I could
take a look at it and learn?
i'm new to python and programming in general. i'm working on some
algorithmic composition stuff and also trying to write some synths....
here's my email...
da********@yaho o.com
Sep 1 '06 #5
Jay
So, are you saying this would be possible to do with the PlaySound
function?

Fredrik Lundh wrote:
Ben Sizer wrote:
Not really. You'll have to convert it to .wav and then pass it to a
helper app.

<http://www.microsoft.c om/technet/scriptcenter/resources/qanda/nov04/hey1103.mspx>
>import winsound
help(winsoun d)
Help on module winsound:

NAME
winsound

FILE
c:\python24\dll s\winsound.pyd

DESCRIPTION
PlaySound(sound , flags) - play a sound
SND_FILENAME - sound is a wav file name
SND_ALIAS - sound is a registry sound association name
SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC
SND_MEMORY - sound is a memory image of a wav file
SND_PURGE - stop all instances of the specified sound
SND_ASYNC - PlaySound returns immediately
SND_NODEFAULT - Do not play a default beep if the sound can not be found
SND_NOSTOP - Do not interrupt any sounds currently playing
SND_NOWAIT - Return immediately if the sound driver is busy

Beep(frequency, duration) - Make a beep through the PC speaker.

FUNCTIONS
Beep(...)
Beep(frequency, duration) - a wrapper around the Windows Beep API

The frequency argument specifies frequency, in hertz, of the sound.
This parameter must be in the range 37 through 32,767.
The duration argument specifies the number of milliseconds.
On WinNT and 2000, the platform Beep API is used directly. Else funky
code doing direct port manipulation is used; it's unknown whether that
will work on all systems.

MessageBeep(... )
MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK.

PlaySound(...)
PlaySound(sound , flags) - a wrapper around the Windows PlaySound API

The sound argument can be a filename, data, or None.
For flag values, ored together, see module documentation.

DATA
MB_ICONASTERISK = 64L
MB_ICONEXCLAMAT ION = 48L
MB_ICONHAND = 16L
MB_ICONQUESTION = 32L
MB_OK = 0L
SND_ALIAS = 65536L
SND_APPLICATION = 128L
SND_ASYNC = 1L
SND_FILENAME = 131072L
SND_LOOP = 8L
SND_MEMORY = 4L
SND_NODEFAULT = 2L
SND_NOSTOP = 16L
SND_NOWAIT = 8192L
SND_PURGE = 64L

</F>
Sep 1 '06 #6
Jay wrote:
So, are you saying this would be possible to do with the PlaySound
function?
Fredrik is often terse. ;) I think what he's saying is that when I
said you could pass a .wav file to an external application, he showed
that you could pass it to a Python module instead. I think you still
need to get it into .wav format first, though this can apparently be in
memory rather than on disk.

--
Ben Sizer

Sep 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3025
by: Noah | last post by:
I need to record raw 8-bit mono audio from a generic sound card on MS-Windows. I need to do something like this: sound_device = open audio device buffer = sound_device.read ('1 second, 8 bit, mono, 8 KHz') process buffer If possible I would also like to experiment with sampling the raw audio in my own loop. For example, something like this: open audio device while 1:
7
4773
by: psk | last post by:
Hi, I need to read live audio from microphone and somehow make data packets from it and send using my client-server implementation where it will be played. Can anyone tell me abt any available C libraries to read the audio from mic and encode it.....and finally make a data packet as an input for my client server application ???
4
6300
by: hzgt9b | last post by:
Using VS 2003, VB.NET and/or ASP.NET 2.0, BACKGROUND I have a window forms based application that contains a TreeView control and a WebBroswer (AxSHDocVw.AxWebBrowser) control. The TreeView is populated with nodes that when clicked play an audio clip from specified local or web URL and navigate the browser control to a specified local or web URL. Audio playback uses as hidden media player object AxWMPLib.AxWindowsMediaPlayer).
1
3510
by: Karthik | last post by:
Hi, I have been using GDI+ and Windows Media SDK to get the metadata information for image and audio files respectively. Just incase if someone is not clear as to what I mean by metadata information, its the information regarding the image or audio files like., height and width for the image.,. Title, artist, author etc for the audio files.
4
1676
by: =?Utf-8?B?U2F0eWE=?= | last post by:
My PC crashed and I have installed windows XP SP2 again. Now audio is distored (it runs too fast) with all applications like Windows Media Player, Real Player, WIN DVD player, CD player. etc. What would solve this?
8
3100
by: Tony K | last post by:
Is streaming audio capable in asp.net 2.0 / AJAX? What I mean by streaming audio is: ability to play one or more songs back to back...or maybe even let the user select several songs to play and it will play them back to back. Thanks, Tony K
1
1740
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
I am using Windows Media Player to play my half second audio files one after the other using the code below... My problem comes when I play a second audio file immediately after the first one stops sometimes on slower computers the audio on the second file gets truncated on the beginning of playing the second file. What can I do to minimize this truncation of audio? Right now I am having to add 1 second of blank audio to the beginning...
3
3338
by: Dilip1983 | last post by:
Hi, I am unable to install ac 97 realtek audio driver in my system(Windows XP). Earlier i tried to install Realtek Audio Driver in Windows XP which gave me error(Install Realtek HD Audio Driver Failure !!). Then i tried to install ac 97 realtek audio driver. The audio driver got installed in my system but sound is not coming. Please provide me some suggestions.
3
3443
by: AWW | last post by:
Using XP and VB 2005, it seemed like a good idea to save audio in the clipboard and then play it with backgroundworker. Cannot find a good Clipboard audio example anywhere - just SetAudio and GetAudio. And an example seems to do a SwapAudio which makes no sense. Basically I want to spool or simulate spooling of audio. So is this reasonable for asynchronous audio clip play? or alternate? Any thoughts or pointers to other sources? Thanks.
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.