python3 写一个WAV音频文件播放器的代码
作者:sunlightwizard 时间:2023-04-09 05:06:36
环境:ubuntu 16.04 python3.5 pycharm
包 : wave pyaudio sys
上代码:AudioPlayer.py
# coding:utf-8
# author:king
# brief : 播放wav音频文件
import wave
from pyaudio import PyAudio
import sys
def player(filename):
chunk = 1024
wf = wave.open(filename, 'rb')
p = PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(),
rate=wf.getframerate(), output=True)
data = wf.readframes(chunk)
print(data)
while data != b'':
data = wf.readframes(chunk)
stream.write(data)
stream.stop_stream()
stream.close()
p.terminate()
if __name__ == '__main__':
audiofile = sys.argv[1];
player(audiofile);
使用方法是直接用pyinstaller 生成可执行文件
pyinstaller -F AudioPlayer.py
在dist下即可找到生成的可执行文件复制到/usr/bin/下即可使用
使用方法是 AudioPlayer dingwav
总结
以上所述是小编给大家介绍的python3 写一个WAV音频文件播放器的代码,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/u012805073/article/details/101303518
标签:python,音频,播放器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
语义化的HTML结构到底有何好处?
2009-07-13 12:38:00
Python3获取拉勾网招聘信息的方法实例
2022-06-28 00:57:11
![](https://img.aspxhome.com/file/2023/3/112803_0s.jpg)
Golang基础教程之字符串string实例详解
2024-02-07 22:37:10
![](https://img.aspxhome.com/file/2023/7/108087_0s.png)
PHP面向对象程序设计之类与反射API详解
2023-11-19 12:44:12
MSSQL 游标使用 心得
2024-01-21 02:00:48
Python 合并拼接字符串的方法
2022-05-26 08:58:08
基于jupyter代码无法在pycharm中运行的解决方法
2023-09-15 06:46:38
![](https://img.aspxhome.com/file/2023/1/112761_0s.jpg)
JS数组返回去重后数据的方法解析
2024-05-02 17:40:10
前端开发之JS生成32位随机数的方法举例
2024-04-19 09:56:26
![](https://img.aspxhome.com/file/2023/2/136002_0s.png)
python不同版本的_new_不同点总结
2023-09-21 15:36:45
编写脚本令Xtrabackup对MySQL数据进行备份的教程
2024-01-16 06:38:25
![](https://img.aspxhome.com/file/2023/7/113997_0s.jpg)
详解vue-router2.0动态路由获取参数
2024-04-09 10:49:42
![](https://img.aspxhome.com/file/2023/1/139731_0s.png)
python双向链表实现实例代码
2023-05-16 09:38:54
![](https://img.aspxhome.com/file/2023/8/99218_0s.jpg)
用python生成mysql数据库结构文档
2021-05-15 12:04:33
![](https://img.aspxhome.com/file/2023/5/67945_0s.png)
C#中使用SQLite数据库的方法介绍
2024-01-26 00:31:49
Python实现监控内存使用情况和代码执行时间
2023-05-02 15:42:02
![](https://img.aspxhome.com/file/2023/8/90948_0s.jpg)
PhpStorm配置debug环境的详细过程
2023-05-26 20:04:32
在ASP处理程序时,进度显示
2008-08-04 13:27:00
oracle sqlplus 常用命令大全
2009-05-24 19:47:00
Django跨域请求CSRF的方法示例
2021-07-13 21:09:34