winsound — Interface de reprodução de som para Windows¶
O módulo winsound fornece acesso ao mecanismo básico de reprodução de som fornecido pelas plataformas Windows. Inclui funções e várias constantes.
-
winsound.Beep(frequency, duration)¶ Emite um bipe no alto-falante do PC. O parâmetro frequency especifica a frequência, em hertz, do som e deve estar no intervalo de 37 a 32.767. O parâmetro duration especifica o número de milissegundos que o som deve durar. Se o sistema não conseguir emitir um bipe no alto-falante,
RuntimeErroré levantado.
-
winsound.PlaySound(sound, flags)¶ Call the underlying
PlaySound()function from the Platform API. The sound parameter may be a filename, a system sound alias, audio data as a bytes-like object, orNone. Its interpretation depends on the value of flags, which can be a bitwise ORed combination of the constants described below. If the sound parameter isNone, any currently playing waveform sound is stopped. If the system indicates an error,RuntimeErroris raised.
-
winsound.MessageBeep(type=MB_OK)¶ Call the underlying
MessageBeep()function from the Platform API. This plays a sound as specified in the registry. The type argument specifies which sound to play; possible values are-1,MB_ICONASTERISK,MB_ICONEXCLAMATION,MB_ICONHAND,MB_ICONQUESTION, andMB_OK, all described below. The value-1produces a “simple beep”; this is the final fallback if a sound cannot be played otherwise. If the system indicates an error,RuntimeErroris raised.
-
winsound.SND_ALIAS¶ The sound parameter is a sound association name from the registry. If the registry contains no such name, play the system default sound unless
SND_NODEFAULTis also specified. If no default sound is registered, raiseRuntimeError. Do not use withSND_FILENAME.All Win32 systems support at least the following; most systems support many more:
PlaySound()nameCorresponding Control Panel Sound name
'SystemAsterisk'Asterisk
'SystemExclamation'Exclamation
'SystemExit'Exit Windows
'SystemHand'Critical Stop
'SystemQuestion'Question
Por exemplo:
import winsound # Play Windows exit sound. winsound.PlaySound("SystemExit", winsound.SND_ALIAS) # Probably play Windows default sound, if any is registered (because # "*" probably isn't the registered name of any sound). winsound.PlaySound("*", winsound.SND_ALIAS)
-
winsound.SND_LOOP¶ Play the sound repeatedly. The
SND_ASYNCflag must also be used to avoid blocking. Cannot be used withSND_MEMORY.
-
winsound.SND_MEMORY¶ The sound parameter to
PlaySound()is a memory image of a WAV file, as a bytes-like object.Nota
This module does not support playing from a memory image asynchronously, so a combination of this flag and
SND_ASYNCwill raiseRuntimeError.
-
winsound.SND_PURGE¶ Stop playing all instances of the specified sound.
Nota
This flag is not supported on modern Windows platforms.
-
winsound.SND_ASYNC¶ Return immediately, allowing sounds to play asynchronously.
-
winsound.SND_NODEFAULT¶ If the specified sound cannot be found, do not play the system default sound.
-
winsound.SND_NOSTOP¶ Do not interrupt sounds currently playing.
-
winsound.SND_NOWAIT¶ Return immediately if the sound driver is busy.
Nota
This flag is not supported on modern Windows platforms.
-
winsound.MB_ICONASTERISK¶ Play the
SystemDefaultsound.
-
winsound.MB_ICONEXCLAMATION¶ Play the
SystemExclamationsound.
-
winsound.MB_ICONHAND¶ Play the
SystemHandsound.
-
winsound.MB_ICONQUESTION¶ Play the
SystemQuestionsound.
-
winsound.MB_OK¶ Play the
SystemDefaultsound.