日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2024/9/30 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pygame.mixer.Sound()语句提示错误:pygame.error: Unable to open file 'test.wav' 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

環(huán)境:Win10、python3.6.5、pygame( version 1.9.3)

在使用pygame創(chuàng)建一個(gè)wav文件時(shí),代碼如下:

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)

在使用時(shí)提示如下錯(cuò)誤:

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.

可知,用法應(yīng)該是沒有過時(shí)的,并且是正確的。
那么問題出在哪呢?查一下錯(cuò)誤提示,找到網(wǎng)頁(yè):

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

這個(gè)說是沒有初始化,但我的代碼中將初始化放在__init__() 函數(shù)中了,不應(yīng)該提示錯(cuò)誤,然后還有的同學(xué)說是

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支持不了那么高頻的數(shù)據(jù),然后我就將我的代碼中的頻率降為128,結(jié)果依然提示錯(cuò)誤。說明問題還不在這。那么問題出在哪呢?
繼續(xù)找,終于在這個(gè)網(wǎng)頁(yè)(https://blog.csdn.net/ltime/article/details/72473138)上找到了。
原因是我用的公司的臺(tái)式電腦,上面沒有音頻設(shè)備,硬件不支持,拿一個(gè)耳機(jī)連接上電腦,再次運(yùn)行,成功,但是和網(wǎng)頁(yè)上那位作者遇到的問題不一樣的是我的錯(cuò)誤始終提示的是

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

而那位作者提示的卻是

pygame.error: DirectSoundCreate: No audio device found

這樣的錯(cuò)誤真是簡(jiǎn)單明了。

與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的pygame.mixer.Sound()语句提示错误:pygame.error: Unable to open file 'test.wav'的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。