Skip to content

Commit

Permalink
microphone selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Novecento99 committed Jul 30, 2024
1 parent c456c91 commit a18f9c3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/soundMonitorGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,25 @@ def __init__(self):
self.triggerCheck = QCheckBox("enable trigger")
self.multiplier = QLineEdit("100")
self.volumeBar = QProgressBar()
self.feedbackLabel = QLabel()
self.volumeBar.setOrientation(Qt.Orientation.Vertical)
self.inputSelector = QComboBox()
self.inputSelector.addItems(set([device["name"][0:80] for device in self.inputDevices]))
self.inputSelector.addItems([(str(device["index"]).format("%02d",7)+" "+device["name"]) for device in self.inputDevices])
self.inputSelector.setCurrentText(sd.query_devices()[1]["name"])

print(sd.default.device)
print(sd.query_devices())


self.outputSelector = QComboBox()
self.outputSelector.addItems(set([device["name"][0:80] for device in self.outputDevices]))
self.outputSelector.addItems(([device["name"] for device in self.outputDevices]))
self.outputSelector.setCurrentText(sd.query_devices()[4]["name"])
self.debugButton = QPushButton("debug")
self.options = QCheckBox("show options")



self.inputSelector.currentIndexChanged.connect(self.ChangeInput)
self.inputSelector.currentIndexChanged.connect(self.restartInput)

self.volumeBar.setStyleSheet("""
QProgressBar {
Expand All @@ -76,6 +77,7 @@ def __init__(self):

self.masterGrid.addWidget(self.debugButton)
self.masterGrid.addWidget(self.options)
self.masterGrid.addWidget(self.feedbackLabel)
self.masterGrid.addWidget(self.volumeBar,0,1,-1,1)
self.widget.setLayout(self.masterGrid)

Expand All @@ -90,10 +92,19 @@ def __init__(self):

# Start the audio stream
self.stream = sd.InputStream(callback=self.ListenToMic)
self.stream.start()

def ChangeInput(self):
1+1
self.restartInput()

def restartInput(self):
if self.stream.active:
self.stream.close()
try:
sd.default.device = int(self.inputSelector.currentText()[0:2])
self.stream = sd.InputStream(callback=self.ListenToMic)
self.stream.start()
self.feedbackLabel.setText("Started")
except KeyError as e:
self.feedbackLabel.setText("Not valid")
print(e)

def Debug(self):
self.PlayTone()
Expand Down Expand Up @@ -139,6 +150,6 @@ def PlayTone(self, freq=2500, duration=0.2, samplerate=44100, amplitude=0.5):
app.setFont(font)
listenerWindow = micMonitorWindow()
listenerWindow.show()

app.exec()
listenerWindow.stream.close()

0 comments on commit a18f9c3

Please sign in to comment.