1 \section{\module{winsound
} ---
2 Sound-playing interface for Windows
}
4 \declaremodule{builtin
}{winsound
}
6 \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
}
12 The
\module{winsound
} module provides access to the basic
13 sound-playing machinery provided by Windows platforms. It includes
14 two functions and several constants.
17 \begin{funcdesc
}{Beep
}{frequency, duration
}
18 Beep the PC's speaker.
19 The
\var{frequency
} parameter specifies frequency, in hertz, of the
20 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
23 able to beep the speaker,
\exception{RuntimeError
} is raised.
24 \note{Under Windows
95 and
98, the Windows
\cfunction{Beep()
}
25 function exists but is useless (it ignores its arguments). In that
26 case Python simulates it via direct port manipulation (added in version
27 2.1). It's unknown whether that will work on all systems.
}
31 \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.
41 \begin{datadesc
}{SND_FILENAME
}
42 The
\var{sound
} parameter is the name of a WAV file.
43 Do not use with
\constant{SND_ALIAS
}.
46 \begin{datadesc
}{SND_ALIAS
}
47 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
}.
53 All Win32 systems support at least the following; most systems support
56 \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
}
70 # Play Windows exit sound.
71 winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
73 # Probably play Windows default sound, if any is registered (because
74 # "*" probably isn't the registered name of any sound).
75 winsound.PlaySound("*", winsound.SND_ALIAS)
79 \begin{datadesc
}{SND_LOOP
}
80 Play the sound repeatedly. The
\constant{SND_ASYNC
} flag must also
81 be used to avoid blocking. Cannot be used with
\constant{SND_MEMORY
}.
84 \begin{datadesc
}{SND_MEMORY
}
85 The
\var{sound
} parameter to
\function{PlaySound()
} is a memory
86 image of a WAV file, as a string.
88 \note{This module does not support playing from a memory
89 image asynchronously, so a combination of this flag and
90 \constant{SND_ASYNC
} will raise
\exception{RuntimeError
}.
}
93 \begin{datadesc
}{SND_PURGE
}
94 Stop playing all instances of the specified sound.
97 \begin{datadesc
}{SND_ASYNC
}
98 Return immediately, allowing sounds to play asynchronously.
101 \begin{datadesc
}{SND_NODEFAULT
}
102 If the specified sound cannot be found, do not play the system default
106 \begin{datadesc
}{SND_NOSTOP
}
107 Do not interrupt sounds currently playing.
110 \begin{datadesc
}{SND_NOWAIT
}
111 Return immediately if the sound driver is busy.