环境:Win10、python3.6.5、pygame( version 1.9.3)

在使用pygame创建一个wav文件时,代码如下:

import pygame
class Player:# constructordef __init__(self):pygame.mixer.pre_init(44100, -16, 1, 2048)pygame.init()# add a notedef add(self, fileName):self.notes[fileName] = pygame.mixer.Sound(fileName)

在使用时提示如下错误:

pygame.error: Unable to open file 'test.wav'

查阅资料:

pygame.mixer.Sound
Create a new Sound object from a file or buffer object

Note: The buffer will be copied internally, no data will be shared between it and the Sound object.

可知,用法应该是没有过时的,并且是正确的。
那么问题出在哪呢?查一下错误提示,找到网页:

You cannot use pygames’ library’s unless you initialize either the modules your using or all of pygame.

这个说是没有初始化,但我的代码中将初始化放在__init__() 函数中了,不应该提示错误,然后还有的同学说是

It turned out that the frequency rate was too high for pygame, so I used one of the free tools to reduce the sampling rate (to smth like 128 bps) and it worked.

也就是说pygame支持不了那么高频的数据,然后我就将我的代码中的频率降为128,结果依然提示错误。说明问题还不在这。那么问题出在哪呢?
继续找,终于在这个网页(https://blog.csdn.net/ltime/article/details/72473138)上找到了。
原因是我用的公司的台式电脑,上面没有音频设备,硬件不支持,拿一个耳机连接上电脑,再次运行,成功,但是和网页上那位作者遇到的问题不一样的是我的错误始终提示的是

pygame.error: Unable to open file 'test.wav'

而那位作者提示的却是

pygame.error: DirectSoundCreate: No audio device found

这样的错误真是简单明了。

pygame.mixer.Sound()语句提示错误:pygame.error: Unable to open file 'test.wav'相关推荐

  1. jmeter导入jar包提示错误:ERROR o.a.j.JMeter: Uncaught exception

    jmeter导入jar包提示错误:ERROR o.a.j.JMeter: Uncaught exception 1.jmeter导入jar包后,运行后 提示如下错误 2020-06-29 11:13: ...

  2. Qt开发(三) Qt调试运行提示::-1: error: cannot open output file debug\untitled.exe: Permission denied

    在Qt Create 中开发项目时,有时候编译并运行会提示: :-1: error: cannot open output file debug\untitled.exe: Permission de ...

  3. linux 内核编译错误 gcc: error: elf_i386: No such file or directory

    编译内核出现以下错误 CC arch/x86/mm/mmio-mod.oLD arch/x86/mm/mmiotrace.oLD arch/x86/mm/built-in.oCC arch/x86/c ...

  4. ionic build Android错误记录 error in opening zip file

    0.写在前头 运行 :cordova requirements Requirements check results for android: Java JDK: installed 1.8.0 An ...

  5. 错误解析 error:unable to find numeric literal operator ‘operator““a/b/c/...‘

    当出现 error:unable to find numeric literal operator 'operator""c'或者 'b8'/ 'xx' was not decla ...

  6. mysql upgrade错误,升级mysql_upgrade 提示错误FATAL ERROR: Upgrade failed的原因

    用mysql_upgrade 升级mysql的两种错误: 第一种. 提示FATAL ERROR:Upgrade failed 的时候时候输入mysql升级命令并输入密码后出现下面的错误提示: [roo ...

  7. unity中发布android时候出现这样的提示错误:error:device not found

    原因很简单,就是你没开启安卓设备,无论是安卓手机还是安卓虚拟器.. 解决办法:只要开启安卓虚拟器或者连接手机即可 再次打开cmd命令窗口,找到apk文件所在路径,例如: D: 回车(我的是在d盘根目录 ...

  8. Permission denied error: unable to index file .vs/Trip2015/v15/Server/sqlite3/db.lock fatal: adding

    参考:http://www.learnmsnet.com/post/Git-Commit-dblock-error-on-every-commit .net项目提交代码执行 git add . 时出现 ...

  9. Pygame mixer 模块

    pygame.mixer 用于加载和播放声音的pygame模块 函数 pygame.mixer.init  -  初始化混音器模块 pygame.mixer.pre_init  -  预设混音器初始化 ...

最新文章

  1. IT十八掌作业_java基础第八天_多线程
  2. 关于MetaAPI问题CSDN给的邮件回复
  3. python gridview_Python笔记
  4. The Linux Storage Stack Diagram
  5. 解决安卓中页脚被输入法顶起的问题
  6. 武汉大学计算机考研复试考什么,2018武汉大学计算机考研复试经验贴
  7. bim计算机考试,“全国BIM技能等级考试”三级(建筑设计)样题
  8. 一个比较隐蔽热门的微信解封项目
  9. EYOUCMS常用标签(官方很慢找的一些,持续更新,建议收藏)
  10. 航天器轨迹预测——根据速度和位置确定初轨
  11. 本地 Git 文件夹显示绿色标识
  12. office起动缓慢_如何解决Microsoft Outlook启动缓慢的问题
  13. .bat脚本执行cmd命令
  14. vue+draggable +jsPlumb 表格数据连线
  15. 在资源管理器中隐藏指定分区
  16. OpenGL ply
  17. VUE 首屏加载时间优化
  18. mp4视频太大怎么压缩?
  19. 如何用Serverless搭建Mock Server?
  20. 全志H616开发板Orange Pi Zero2连接香橙派5寸TFT液晶屏的测试说明

热门文章

  1. TensorFlow 教程——基本分类:对服装图像进行分类
  2. JavaScript + Tampermonkey——易班优课YOOC课群在线测试自动答题解决方案(十七)复合型解决方案油猴脚本
  3. Web Security——英语写作与教学评价系统(iWrite)解决写作时禁止复制粘贴问题解决方案
  4. 最长不下降子序列问题
  5. Minimum Array
  6. Increasing Subsequence (easy version)
  7. Be Positive
  8. Fence Repair
  9. JavaWeb-综合案例(用户信息)-学习笔记04【删除选中功能】
  10. 一图读懂Java架构