[英]How do I take user input "n = str(input("Give str"))" while having the numpy module imported?
my problem is that I can't take input from user ("n = str(input("Give str"))") while having the numpy module imported.我的问题是在导入 numpy 模块时我无法从用户 ("n = str(input("Give str"))") 获取输入。 I'm new to basically everything in Python and can't get past this problem.
我对 Python 中的所有内容基本上都是新手,无法解决这个问题。
No matter what I do,不管我做什么,
"TypeError: 'numpy.ndarray' object is not callable".
The borrowed code I am working with:我正在使用的借用代码:
import pyaudio
import numpy as np
noteslist = {"C":-10,"C#":-9,"D":-8,"D#":-7,"E":-6,"E#":-5,"F":-4,"F#":-3,"G":-2,"G#":-1,"A":0,"A#":1,"B":2}
n = input("Give")
fs = 44100
duration = 5.0
f = 432.0
#Until this point I need to be albe to code as if no modules (numpy) have been imported.
#Part 2 of the code
input = np.sin(2*np.pi*np.arange(fs*duration)*f/fs)
def play(input):
sample = (input).astype(np.float32)
volume = 0.25
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*sample)
stream.stop_stream()
stream.close()
p.terminate()
play(input)
Ideas on how to overcome this problem although I have no idea how to realise them:关于如何克服这个问题的想法虽然我不知道如何实现它们:
Thanks so much!非常感谢!
input
is a built-in function in python. input
是python中的内置函数。
Reference: https://docs.python.org/3/library/functions.html#input参考: https ://docs.python.org/3/library/functions.html#input
You are currently using it as a variable for your numpy
array.您当前正在将它用作
numpy
数组的变量。
This will not work.这行不通。
Instead rename it to another variable.而是将其重命名为另一个变量。
Consider this updated code.考虑这个更新的代码。
import pyaudio
import numpy as np
noteslist = {
"C": -10,
"C#": -9,
"D": -8,
"D#": -7,
"E": -6,
"E#": -5,
"F": -4,
"F#": -3,
"G": -2,
"G#": -1,
"A": 0,
"A#": 1,
"B": 2,
}
n = input("Give")
fs = 44100
duration = 5.0
f = 432.0
A = np.sin(2 * np.pi * np.arange(fs * duration) * f / fs)
def play(A):
sample = (A).astype(np.float32)
volume = 0.25
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume * sample)
stream.stop_stream()
stream.close()
p.terminate()
play(A)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.