32.4. winsound – интерфейс воспроизведения звука для Windows¶winsound – Sound-playing interface for Windows
Платформы: Windows
Модуль winsound предоставляет доступ к основным механизмам воспроизведения звука, предоставляемым платформами Windows. Он включает функции и несколько констант.
- winsound.Beep(frequency, duration)¶
- Beep the PC’s speaker. The frequency parameter specifies frequency, in hertz, of the sound, and must be in the range 37 through 32,767. The duration parameter specifies the number of milliseconds the sound should last. If the system is not able to beep the speaker, RuntimeError is raised.
- winsound.PlaySound(sound, flags)¶
- Call the underlying PlaySound() function from the Platform API. The sound parameter may be a filename, audio data as a string, or None. Its interpretation depends on the value of flags, which can be a bitwise ORed combination of the constants described below. If the sound parameter is None, any currently playing waveform sound is stopped. If the system indicates an error, RuntimeError is 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, and MB_OK, all described below. The value -1 produces a “simple beep”; this is the final fallback if a sound cannot be played otherwise.
- 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_NODEFAULT is also specified. If no default sound is registered, raise RuntimeError. Do not use with SND_FILENAME.
Все системы Win32 поддерживают как минимум следующее; большинство систем поддерживают ещё много других:
PlaySound() name Соответствующее название звука в панели управления 'SystemAsterisk' Звёздочка 'SystemExclamation' Восклицание 'SystemExit' Выход из Windows 'SystemHand' Критическая остановка 'SystemQuestion' Вопрос Например:
import winsound # Воспроизвести звук выхода из Windows. winsound.PlaySound("SystemExit", winsound.SND_ALIAS) # Вероятно, воспроизводит звук Windows по умолчанию, если таковой зарегистрирован (поскольку # "*" скорее всего не является зарегистрированным именем какого-либо звука). winsound.PlaySound("*", winsound.SND_ALIAS)
- winsound.SND_LOOP¶
- Play the sound repeatedly. The SND_ASYNC flag must also be used to avoid blocking. Cannot be used with SND_MEMORY.
- winsound.SND_MEMORY¶
The sound parameter to PlaySound() is a memory image of a WAV file, as a string.
Примечание
This module does not support playing from a memory image asynchronously, so a combination of this flag and SND_ASYNC will raise RuntimeError.
- winsound.SND_PURGE¶
Останавливает воспроизведение всех экземпляров указанного звука.
Примечание
Этот флаг не поддерживается на современных платформах Windows.
- winsound.SND_ASYNC¶
- Возвращает управление немедленно, позволяя звукам воспроизводиться асинхронно.
- winsound.SND_NODEFAULT¶
- Если указанный звук не найден, не воспроизводить системный звук по умолчанию.
- winsound.SND_NOSTOP¶
- Не прерывать звуки, воспроизводимые в данный момент.
- winsound.SND_NOWAIT¶
- Возвращать управление немедленно, если звуковой драйвер занят.
- winsound.MB_ICONASTERISK¶
- Воспроизвести звук SystemDefault.
- winsound.MB_ICONEXCLAMATION¶
- Воспроизвести звук SystemExclamation.
- winsound.MB_ICONHAND¶
- Воспроизвести звук SystemHand.
- winsound.MB_ICONQUESTION¶
- Воспроизвести звук SystemQuestion.
- winsound.MB_OK¶
- Воспроизвести звук SystemDefault.