Forwarded from column Liu Xin: python _ simple sound playback function

Source: Internet
Author: User

Http://blog.csdn.net/jj_liuxin/archive/2008/12/21/3574638.aspx

Just take a look at the python 3.0 documentation and find a very pythonic module: sound playback for windows; a buzzword called "silly and naive", which is quite easy.

1> winsound. BEEP
2> winsound. playsound ()

Each one has a different usage. Let's look at it one by one.
1> winsound. Beep (frequency, duration)
The PC speaker just gave it a drop. The first parameter, frequency, indicates the number of decibels. The value ranges from 37 to 32767. The second parameter is duration, in milliseconds (if you are patient, try winsound. Beep (32767,99999), ).
2> winsound. playsound

  1. Import
    Winsound
  2. # Play windows exit sound.
  3. Winsound. playsound (
    "Systemexit"
    , Winsound. snd_alias)
  4. # Probably play Windows Default sound, if any is registered (because
  5. # "*" Probably isn' t the registered name of any sound ).
  6. Winsound. PlaySound (
    "*"
    , Winsound. SND_ALIAS)

However, only wav files can be played, and WMA and MP3 files cannot be played. These two types also require support from other packages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.