34.4. winsound --- Windows 用の音声再生インタフェース¶
winsound モジュールは Windows プラットフォーム上で提供されている基本的な音声再生機構へのアクセス手段を提供します。このモジュールではいくつかの関数と定数が定義されています。
- 
winsound.Beep(frequency, duration)¶
- PC のスピーカを鳴らします。引数 frequency は鳴らす音の周波数の指定で、単位は Hz です。値は 37 から 32,767 でなくてはなりません。引数 duration は音を何ミリ秒鳴らすかの指定です。システムがスピーカを鳴らすことができない場合、例外 - RuntimeErrorが送出されます。
- 
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,- 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, and- MB_OK, all described below. The value- -1produces a "simple beep"; this is the final fallback if a sound cannot be played otherwise.
- 
winsound.SND_ALIAS¶
- 引数 sound はレジストリにある音声データに関連付けられた名前であることを示します。指定した名前がレジストリ上にない場合、定数 - SND_NODEFAULTが同時に指定されていない限り、システム標準の音声データが再生されます。標準の音声データが登録されていない場合、例外- RuntimeErrorが送出されます。- SND_FILENAMEと同時に使ってはいけません。- 全ての Win32 システムは少なくとも以下の名前をサポートします; ほとんどのシステムでは他に多数あります: - PlaySound()name- 対応するコントロールパネルでの音声名 - 'SystemAsterisk'- Asterisk - 'SystemExclamation'- Exclamation - 'SystemExit'- Exit Windows - 'SystemHand'- Critical Stop - 'SystemQuestion'- Question - 例えば: - 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¶
- 音声データを繰り返し再生します。システムがブロックしないようにするため、 - SND_ASYNCフラグを同時に使わなくてはなりません。- SND_MEMORYと同時に使うことはできません。
- 
winsound.SND_MEMORY¶
- The sound parameter to - PlaySound()is a memory image of a WAV file, as a string.- 注釈 - このモジュールはメモリ上のイメージを非同期に再生する機能をサポートしていません。従って、このフラグと - SND_ASYNCを組み合わせると例外- RuntimeErrorが送出されます。
- 
winsound.SND_PURGE¶
- 指定した音声の全てのインスタンスについて再生処理を停止します。 - 注釈 - このフラグは現代のWindowsプラットフォームではサポートされていません。 
- 
winsound.SND_ASYNC¶
- 音声を非同期に再生するようにして、関数呼び出しを即座に返します。 
- 
winsound.SND_NODEFAULT¶
- 指定した音声が見つからなかった場合にシステム標準の音声を鳴らさないようにします。 
- 
winsound.SND_NOSTOP¶
- 現在鳴っている音声を中断させないようにします。 
- 
winsound.SND_NOWAIT¶
- サウンドドライバがビジー状態にある場合、関数がすぐ返るようにします。 - 注釈 - このフラグは現代のWindowsプラットフォームではサポートされていません。 
- 
winsound.MB_ICONASTERISK¶
- 音声 - SystemDefaultを再生します。
- 
winsound.MB_ICONEXCLAMATION¶
- 音声 - SystemExclamationを再生します。
- 
winsound.MB_ICONHAND¶
- 音声 - SystemHandを再生します。
- 
winsound.MB_ICONQUESTION¶
- 音声 - SystemQuestionを再生します。
- 
winsound.MB_OK¶
- 音声 - SystemDefaultを再生します。
