Python uses wxPython to open and play wav files

Source: Internet
Author: User

Python uses wxPython to open and play wav files

Python uses wxPython to open and play wav files

This article describes how to use wxPython to open and play wav files. It involves python-related techniques for operating audio files. For more information, see

This example describes how to use wxPython to open and play wav files. Share it with you for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

'''Wx_lib_filebrowsebutton_sound.py

Select a sound file and play it

Wx. lib. filebrowsebutton. FileBrowseButton (parent, labelText, fileMask)

(Combines wx. TextCtrl and wxFileDialog widgets)

Wx. Sound (fileName, isResource = False)

Tested with Python27 and wxPython291 by vegaseat 25jul2013

'''

Import wx

Import wx. lib. filebrowsebutton

 

Class MyFrame (wx. Frame ):

Def _ init _ (self, parent, mytitle, mysize ):

Wx. Frame. _ init _ (self, parent, wx. ID_ANY, mytitle,

Size = mysize)

Self. SetBackgroundColour ("green ")

Panel = wx. Panel (self)

# Mask file browser to look for. wav sound files

Self. fbb = wx. lib. filebrowsebutton. FileBrowseButton (panel,

LabelText = "Select a WAVE file:", fileMask = "*. wav ")

Self. play_button = wx. Button (panel, wx. ID_ANY, "> Play ")

Self. play_button.Bind (wx. EVT_BUTTON, self. onPlay)

# Setup the layout with sizers

Hsizer = wx. BoxSizer (wx. HORIZONTAL)

Hsizer. Add (self. fbb, 1, wx. ALIGN_CENTER_VERTICAL)

Hsizer. Add (self. play_button, 0, wx. ALIGN_CENTER_VERTICAL)

 

# Create a border space

Border = wx. BoxSizer (wx. VERTICAL)

Border. Add (hsizer, 0, wx. EXPAND | wx. ALL, 10)

Panel. SetSizer (border)

Def onPlay (self, evt ):

Filename = self. fbb. GetValue ()

Self. sound = wx. Sound (filename)

# Error handling...

If self. sound. IsOk ():

Self. sound. Play (wx. SOUND_ASYNC)

Else:

Wx. MessageBox ("Missing or invalid sound file", "Error ")

App = wx. App (0)

# Create a MyFrame instance and show the frame

Mytitle = "wx. lib. filebrowsebutton and wx. Sound"

Width = 600

Height = 90

MyFrame (None, mytitle, (width, height). Show ()

App. MainLoop ()

I hope this article will help you with Python programming.

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.