ipython 中的 play() 函数未定义
play() function in ipython is undefined
我知道在 ipython 中也有关于播放声音的类似问题,但那些是关于在我尝试在笔记本上创建声音并播放时播放声音文件的问题。如果不确定播放声音的过程是否相同,请原谅我是 ipython.
的新手
代码
samplerate = 44100
duration = 3
t = arange(0, duration, 1/samplerate)
x440 = 0.5*sin(2*pi*440*t)
play(x440)
错误
NameError Traceback (most recent call last)
<ipython-input-31-7e76222fe221> in <module>()
----> 1 play(x440)
NameError: name 'play' is not defined
正如评论中有人提到的,NameError
means that name hasn't been defined anywhere. This means you haven't defined it anywhere. It also isn't a built-in function。不能调用不存在的函数。
您似乎缺少导入。
您需要导入一些音频模块才能播放声音。
在这里您可以找到音频模块列表
From the python official docs
import gym
from gym.utils.play import *
play(gym.make("Pong-v0"))
当你在游戏中时。可以使用KEY"A"和"D"来控制。
我知道在 ipython 中也有关于播放声音的类似问题,但那些是关于在我尝试在笔记本上创建声音并播放时播放声音文件的问题。如果不确定播放声音的过程是否相同,请原谅我是 ipython.
的新手代码
samplerate = 44100
duration = 3
t = arange(0, duration, 1/samplerate)
x440 = 0.5*sin(2*pi*440*t)
play(x440)
错误
NameError Traceback (most recent call last)
<ipython-input-31-7e76222fe221> in <module>()
----> 1 play(x440)
NameError: name 'play' is not defined
正如评论中有人提到的,NameError
means that name hasn't been defined anywhere. This means you haven't defined it anywhere. It also isn't a built-in function。不能调用不存在的函数。
您似乎缺少导入。 您需要导入一些音频模块才能播放声音。 在这里您可以找到音频模块列表 From the python official docs
import gym
from gym.utils.play import *
play(gym.make("Pong-v0"))
当你在游戏中时。可以使用KEY"A"和"D"来控制。