我是靠谱客的博主 自信小笼包,最近开发中收集的这篇文章主要介绍python播放wav文件,播放wav文件python 3,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I want to play a .wav file in Python 3.4. Additonally, I want python to play the file rather than python open the file to play in VLC, media player etc..

As a follow up question, is there any way for me to combine the .wav file and the .py file into a standalone exe.

Ignore the second part of the question if it is stupid, I don't really know anything about compiling python.

Also, I know there have been other questions about .wav files, but I have not found one that works in python 3.4 in the way I described.

解决方案

I fixed the problem by using the module pyaudio, and the module wave to read the file.

I will type example code to play a simple wave file.

import wave, sys, pyaudio

wf = wave.open('Sound1.wav')

p = pyaudio.PyAudio()

chunk = 1024

stream = p.open(format =

p.get_format_from_width(wf.getsampwidth()),

channels = wf.getnchannels(),

rate = wf.getframerate(),

output = True)

data = wf.readframes(chunk)

while data != '':

stream.write(data)

data = wf.readframes(chunk)

最后

以上就是自信小笼包为你收集整理的python播放wav文件,播放wav文件python 3的全部内容,希望文章能够帮你解决python播放wav文件,播放wav文件python 3所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部