blob: 0418c7438f7510d0f7853d06d346a0ac4fe9c1d8 [file] [log] [blame]
Fred Drakec7b72db1999-02-16 19:18:38 +00001\section{\module{winsound} ---
2 Sound-playing interface for Windows}
3
4\declaremodule{builtin}{winsound}
Fred Drakef6863c11999-03-02 16:37:17 +00005 \platform{Windows}
Fred Drakec7b72db1999-02-16 19:18:38 +00006\modulesynopsis{Access to the sound-playing machinery for Windows.}
7\moduleauthor{Toby Dickenson}{htrd90@zepler.org}
8\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
9
Fred Drakef6346341999-02-19 15:46:38 +000010\versionadded{1.5.2}
Fred Drakec7b72db1999-02-16 19:18:38 +000011
12The \module{winsound} module provides access to the basic
Fred Drake714fd261999-10-22 21:08:56 +000013sound-playing machinery provided by Windows platforms. It includes
14two functions and several constants.
Fred Drakec7b72db1999-02-16 19:18:38 +000015
16
Fred Drake714fd261999-10-22 21:08:56 +000017\begin{funcdesc}{Beep}{frequency, duration}
18 Beep the PC's speaker.
19 The \var{frequency} parameter specifies frequency, in hertz, of the
Tim Peters25a9ce32001-02-19 07:06:36 +000020 sound, and must be in the range 37 through 32,767.
21 The \var{duration} parameter specifies the number of milliseconds the
22 sound should last. If the system is not
Fred Drake714fd261999-10-22 21:08:56 +000023 able to beep the speaker, \exception{RuntimeError} is raised.
Fred Drake0aa811c2001-10-20 04:24:09 +000024 \note{Under Windows 95 and 98, the Windows \cfunction{Beep()}
Tim Peters373d1512001-02-19 08:36:41 +000025 function exists but is useless (it ignores its arguments). In that
Tim Peters25a9ce32001-02-19 07:06:36 +000026 case Python simulates it via direct port manipulation (added in version
Fred Drake0aa811c2001-10-20 04:24:09 +000027 2.1). It's unknown whether that will work on all systems.}
Fred Drake29052482001-01-25 17:29:18 +000028 \versionadded{1.6}
Fred Drake714fd261999-10-22 21:08:56 +000029\end{funcdesc}
30
Fred Drakec7b72db1999-02-16 19:18:38 +000031\begin{funcdesc}{PlaySound}{sound, flags}
32 Call the underlying \cfunction{PlaySound()} function from the
33 Platform API. The \var{sound} parameter may be a filename, audio
34 data as a string, or \code{None}. Its interpretation depends on the
35 value of \var{flags}, which can be a bit-wise ORed combination of
36 the constants described below. If the system indicates an error,
37 \exception{RuntimeError} is raised.
38\end{funcdesc}
39
40
41\begin{datadesc}{SND_FILENAME}
42 The \var{sound} parameter is the name of a WAV file.
Tim Peterse79af272001-02-20 10:02:21 +000043 Do not use with \constant{SND_ALIAS}.
Fred Drakec7b72db1999-02-16 19:18:38 +000044\end{datadesc}
45
46\begin{datadesc}{SND_ALIAS}
Fred Drakeafdc8fc2001-02-23 19:10:41 +000047 The \var{sound} parameter is a sound association name from the
48 registry. If the registry contains no such name, play the system
49 default sound unless \constant{SND_NODEFAULT} is also specified.
50 If no default sound is registered, raise \exception{RuntimeError}.
51 Do not use with \constant{SND_FILENAME}.
Tim Peterse79af272001-02-20 10:02:21 +000052
53 All Win32 systems support at least the following; most systems support
54 many more:
55
Fred Drakeafdc8fc2001-02-23 19:10:41 +000056\begin{tableii}{l|l}{code}
57 {\function{PlaySound()} \var{name}}
58 {Corresponding Control Panel Sound name}
59 \lineii{'SystemAsterisk'} {Asterisk}
60 \lineii{'SystemExclamation'}{Exclamation}
61 \lineii{'SystemExit'} {Exit Windows}
62 \lineii{'SystemHand'} {Critical Stop}
63 \lineii{'SystemQuestion'} {Question}
64\end{tableii}
Tim Peterse79af272001-02-20 10:02:21 +000065
Fred Drakeafdc8fc2001-02-23 19:10:41 +000066 For example:
Tim Peterse79af272001-02-20 10:02:21 +000067
Fred Drakeafdc8fc2001-02-23 19:10:41 +000068\begin{verbatim}
69import winsound
70# Play Windows exit sound.
71winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
Tim Peterse79af272001-02-20 10:02:21 +000072
Fred Drakeafdc8fc2001-02-23 19:10:41 +000073# Probably play Windows default sound, if any is registered (because
74# "*" probably isn't the registered name of any sound).
75winsound.PlaySound("*", winsound.SND_ALIAS)
76\end{verbatim}
Fred Drakec7b72db1999-02-16 19:18:38 +000077\end{datadesc}
78
79\begin{datadesc}{SND_LOOP}
80 Play the sound repeatedly. The \constant{SND_ASYNC} flag must also
Tim Peterse79af272001-02-20 10:02:21 +000081 be used to avoid blocking. Cannot be used with \constant{SND_MEMORY}.
Fred Drakec7b72db1999-02-16 19:18:38 +000082\end{datadesc}
83
84\begin{datadesc}{SND_MEMORY}
85 The \var{sound} parameter to \function{PlaySound()} is a memory
Tim Peterse79af272001-02-20 10:02:21 +000086 image of a WAV file, as a string.
Fred Drakec7b72db1999-02-16 19:18:38 +000087
Fred Drake0aa811c2001-10-20 04:24:09 +000088 \note{This module does not support playing from a memory
Thomas Woutersf8316632000-07-16 19:01:10 +000089 image asynchronously, so a combination of this flag and
Fred Drake0aa811c2001-10-20 04:24:09 +000090 \constant{SND_ASYNC} will raise \exception{RuntimeError}.}
Fred Drakec7b72db1999-02-16 19:18:38 +000091\end{datadesc}
92
93\begin{datadesc}{SND_PURGE}
94 Stop playing all instances of the specified sound.
95\end{datadesc}
96
97\begin{datadesc}{SND_ASYNC}
98 Return immediately, allowing sounds to play asynchronously.
99\end{datadesc}
100
101\begin{datadesc}{SND_NODEFAULT}
Tim Peterse79af272001-02-20 10:02:21 +0000102 If the specified sound cannot be found, do not play the system default
103 sound.
Fred Drakec7b72db1999-02-16 19:18:38 +0000104\end{datadesc}
105
106\begin{datadesc}{SND_NOSTOP}
107 Do not interrupt sounds currently playing.
108\end{datadesc}
109
110\begin{datadesc}{SND_NOWAIT}
111 Return immediately if the sound driver is busy.
112\end{datadesc}