- Python Multimedia
- Ninad Sathaye
- 296字
- 2021-08-03 15:27:38
Built-in multimedia support
Python has a few built-in multimedia modules for application development. We will skim through some of these modules.
winsound
The winsound
module is available on the Windows platform. It provides an interface which can be used to implement fundamental audio-playing elements in the application. A sound can be played by calling PlaySound(sound,
flags)
. Here, the argument sound is used to specify the path of an audio file. If this parameter is specified as None
, the presently streaming audio (if any) is stopped. The second argument specifies whether the file to be played is a sound file or a system sound. The following code snippet shows how to play a wave formatted audio file using winsound
module.
from winsound import PlaySound, SND_FILENAME PlaySound("C:/AudioFiles/my_music.wav", SND_FILENAME )
This plays the sound file specified by the first argument to the function PlaySound
. The second argument, SND_FILENAME
, says that the first argument is an audio file. If the flag is set as SND_ALIAS
, it means the value for the first argument is a system sound from the registry.
audioop
This module is used for manipulating the raw audio data. One can perform several useful operations on sound fragments. For example, it can find the minimum and maximum values of all the samples within a sound fragment.
wave
The wave
module provides an interface to read and write audio files with WAV
file format. The following line of code opens a wav file.
import wave fil = wave.open('horn.wav', 'r')
The first argument of method open
is the location where the path to the wave file is specified. The second argument 'r' returns a Wave_read
object. This is the mode in which the audio file is opened, 'r
' or 'rb
' for read-only mode and 'w
' or 'wb
' for write-only mode.
- 突破平面Photoshop UI界面設計與制作剖析
- PS職場達人煉成記:人人都能學會的Photoshop辦公設計技巧
- IBM Cognos 8 Report Studio Cookbook
- 中文版Illustrator 2021完全自學教程
- After Effects全套影視特效制作典型實例(第2版)
- 中文版Photoshop 2020基礎教程
- 圖像處理中的數學修煉(第2版)
- Photoshop 2024從入門到精通
- Learning the Yahoo! User Interface library
- 從零開始:Indesign CC 2019設計基礎+商業設計實戰
- 跨境電商:速賣通搜索排名規則解析與SEO技術
- Photoshop CS6圖像處理立體化教程
- 中文版Illustrator CC完全自學教程
- AutoCAD 2010 建筑設計與制作技能基礎教程
- AutoCAD計算機輔助設計標準教程(慕課版)