-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.py
More file actions
39 lines (33 loc) · 1.14 KB
/
Copy pathrecord.py
File metadata and controls
39 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sounddevice as sd
from pynput import keyboard
import numpy as np
import soundfile as sf
from pydub import AudioSegment
import pygetwindow as gw
# Parameters
duration = 10 # seconds
# Get a list of all input devices
devices = sd.query_devices()
# Find the VoiceMeeter device
voicemeeter_device = None
for idx, device in enumerate(devices):
if 'VoiceMeeter' in device['name']:
voicemeeter_device = idx
# Check if we found the device
if voicemeeter_device is None:
print('Could not find VoiceMeeter device')
exit(1)
# Callback for keyboard listener
def on_press(key):
if str(key) == 'Key.space':
active_window = gw.getActiveWindow()
if "Discord" in active_window.title:
print('Recording...')
myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=2, device=voicemeeter_device)
sd.wait()
sf.write('audio/output.wav', myrecording, fs)
sound = AudioSegment.from_wav('audio/output.wav')
sound.export('audio/output.mp3', format='mp3')
# Setting up keyboard listener
with keyboard.Listener(on_press=on_press) as listener:
listener.join()