我正在制造一个玩具乐器,需要从中反复获取声音,其延迟要小于在c / c ++上使用Python所允许的延迟。不幸的是我可以听到声音,但是控制台告诉我它可以找到DAC或其他东西。 “无效的输出设备”或类似的内容。
import numpy as np
import wave
import struct
import random as random
import pyaudio
from pyaudio import*
import matplotlib.pyplot as plt
import tkinter
from librosa import*
from tkinter import*
#envelope
#Vars
p=pyaudio.PyAudio()
p.get_default_output_device_info()
p.get_device_count()
p.get_host_api_count()
#p.get_host_api_info_by_index()
#p.get_host_api_info_by_type()
amp=10
volume=amp
sr=1000
duration=20
frequency= 440.0
SINON=False
class Window(Frame):
def __init__(self,main=None):
Frame.__init__(self,main)
self.main=main
#self.init_window()
self.main.title("GUI")
self.pack(fill=BOTH,expand=1)
ChooseNoise= Button(self,text="Noise",height=50, width=10)
Sin_button=Button(self,text="sin",height=50, width=10,command=Playnote1)
ChooseCosin= Button(self,text="Cosin",height=50, width=10)
#position buttons
ChooseCosin.grid(row=2,column=0)
ChooseNoise.grid(row=2,column=3)
Sin_button.grid(row=2,column=5)
SINON==False
def Playnote1():
SINON=True
SIN=(np.sin(2*np.pi*np.arange(sr*duration)*frequency/sr))
if SINON==True:
AudioStream= p.open(format=pyaudio.paFloat32,channels=2,rate=sr,output=True)
AudioStream.write(volume*SIN)
AudioStream.stop_stream()
AudioStream.close()
p.terminate()
SINON=False
#controls the maincomponent itself
root= Tk()
root.geometry("200x300")
app= Window(root)
root.mainloop()