0

I know there are similar questions about playing sound in ipython but those are about playing sound files while I'm trying to create a sound on the notebook and play that. If not sure if the process for playing sound is the same regardless sso excuse me as im new to ipython.

Code

samplerate = 44100 
duration = 3 
t = arange(0, duration, 1/samplerate)
x440 = 0.5*sin(2*pi*440*t)
play(x440)

Error

NameError                                 Traceback (most recent call last)
<ipython-input-31-7e76222fe221> in <module>()
----> 1 play(x440)

NameError: name 'play' is not defined
3
  • 2
    pretty obvious error, where have you defined play? Apr 2, 2015 at 11:09
  • any module you are using?? Apr 2, 2015 at 11:45
  • @avinashpandey i haven't imported any. I thought the function was built in.
    – will
    Apr 2, 2015 at 12:31

3 Answers 3

0

As someone mentioned in the comments, a 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. You can't call a function that doesn't exist.

0

Looks like you're missing an import. You need to import some of the audio modules to be able to play sound. Here you can find a list of audio modules From the python official docs

2
  • whats the best way to import them?
    – will
    Apr 2, 2015 at 12:24
  • If you want to be able to create your own audio files, like in your example. This is a great library you can use: Audiolab Apr 2, 2015 at 12:42
0
import gym
from gym.utils.play import *
play(gym.make("Pong-v0"))

While you are in the game. You can use KEY "A" and "D" to control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.