python使用wxPython打开并播放wav文件的方法

   python使用wxPython打开并播放wav文件的方法

        这篇文章主要介绍了python使用wxPython打开并播放wav文件的方法,涉及Python操作音频文件的相关技巧,需要的朋友可以参考下

  本文实例讲述了python使用wxPython打开并播放wav文件的方法。分享给大家供大家参考。具体实现方法如下:

  ?

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()

  希望本文所述对大家的Python程序设计有所帮助。

时间: 2024-08-18 05:23:31

python使用wxPython打开并播放wav文件的方法的相关文章

python使用wxPython打开并播放wav文件的方法_python

本文实例讲述了python使用wxPython打开并播放wav文件的方法.分享给大家供大家参考.具体实现方法如下: ''' 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.So

python通过wxPython打开一个音频文件并播放的方法

 这篇文章主要介绍了python通过wxPython打开一个音频文件并播放的方法,实例分析了wxPython操作音频文件的技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了python通过wxPython打开一个音频文件并播放的方法.分享给大家供大家参考.具体如下: 这段代码片段使用wx.lib.filebrowsebutton.FileBrowseButton控件打开一个wav文件,使用wx.Sound播放 ? 1 2 3 4 5 6 7 8 9 10 11 12 13

python通过wxPython打开一个音频文件并播放的方法_python

本文实例讲述了python通过wxPython打开一个音频文件并播放的方法.分享给大家供大家参考.具体如下: 这段代码片段使用wx.lib.filebrowsebutton.FileBrowseButton控件打开一个wav文件,使用wx.Sound播放 import wx import wx.lib.filebrowsebutton class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__

python 播放 wav 文件

未使用其他库, 只是使用 pywin32 调用系统底层 API 播放 wav 文件. # Our raison d'etre - playing sounds import pywintypes import struct import win32event import win32com.directsound.directsound as ds import os WAV_HEADER_SIZE = struct.calcsize('<4sl4s4slhhllhh4sl') def wav_

js播放wav文件(源码)_javascript技巧

用js播放.wav文件 复制代码 代码如下: <html> <head> <script language="javascript"> function playSound(id) { var node=document.getElementById(id); if(node!=null) { node.Play(); } } </script> </head> <body> <embed name=&quo

java 音频播放-java application 播放wav文件为什么出来的都是噪音,怎么处理呢

问题描述 java application 播放wav文件为什么出来的都是噪音,怎么处理呢 package shanyi; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.*; import sun.audio.*; public class Mysound{ public Mysound(){ t

C# SoundPlayer无法播放wav文件

问题描述 使用SoundPlayer在winform下能正常播放WAV文件,但是把相同代码在C#做的Windows服务中就无法播放wav文件,请问是什么原因?微软BUG吗?SoundPlayerplayer=newSoundPlayer(@"d:1.wav");player.Play(); 解决方案 解决方案二:有没有哪位知道的?

jsp播放视频文件的方法总结_JSP编程

本文实例讲述了jsp播放视频文件的方法.分享给大家供大家参考,具体如下: 1.avi格式 代码片断如下: JSP代码: <object id="video" width="400" height="200" border="0" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"> <param name="ShowDispl

VB打开与保存txt文件的方法_vb

本文实例讲述了VB打开与保存txt文件的方法.分享给大家供大家参考.具体如下: Private Sub cmdsave_Click() Dim filelocation As String ' loads save as box commondialog1.ShowSave filelocation = commondialog1.FileName ' append saves over file if it assists Open filelocation For Append As #1