Compare commits

...

5 Commits

4 changed files with 47 additions and 12 deletions

4
.gitignore vendored
View File

@@ -1 +1,3 @@
*.wav
*.wav
config.json
.vscode

View File

@@ -1 +1,13 @@
# Audio sampler
# Audio sampler
Audio sampler is a tool to record the last `SecondsToRecord` from one or multiple sources. This utility will only record at max stereoaudio.
## Config
`SampleRate` the sample rate to record with, recommended default is `48000`
`SecondsToRecord` amount of seconds to keep in memory and save when triggered.
`SourcesToRecord` a list of audiodevices which will be recorded.
`SaveDirectory` the path of the save folder, meaning the folder they will be saved in.
`Shortcut` the shortcut which will trigger to save the recording.

View File

@@ -3,32 +3,46 @@ import pyaudio, numpy, keyboard, time
import scipy.io.wavfile as wav
from sys import getsizeof
import os
from os.path import exists
import json
import shutil
##### CONFIG #####
##### CONFIG (Now read from file) #####
RATE=48000 # Sample rate
RECORD_SECONDS = 20 # Seconds to record (aka. last X seconds)
SourcesToRecord = ["VoiceMeeter VAIO3 Output"] # Record all sources which contains these strings
SaveDirectory= "D:\AudioSnippetTool\Recordings"
shortcut = 'alt+1'
if(not exists("config.json")):
shutil.copy("config.json.example", "config.json")
print("No config found. Created default config")
##### CONFIG END (aka. DO NOT FRICKING TOUCHY) #####
with open('config.json', 'r') as myfile:
data = myfile.read()
# parse file
conf = json.loads(data)
RATE = conf["SampleRate"] # Sample rate
RECORD_SECONDS = conf["SecondsToRecord"] # Seconds to record (aka. last X seconds)
SourcesToRecord = conf["SourcesToRecord"] # Record all sources which contains these strings
SaveDirectory= conf["SaveDirectory"] # The directory to save to
shortcut = conf["Shortcut"] # The shortcut to trigger the save
##### CONFIG END #####
CHUNKSIZE = 1024*2
print("Searching for audio sources")
Sources = []
AudioChannels = []
Frames = []
p = pyaudio.PyAudio()
p = pyaudio.PyAudio() # An instance of PyAudio
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
numdevices = info.get('deviceCount') # The amount of audio devices
samplesI = 0
saves = 0
cleanUp = False
incomingAudioChan = -1
localAudioChan = -1
## Find the acutal device pointers
## Find the actual device pointers
for i in range(0, numdevices):
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
i2 = 0

7
config.json.example Normal file
View File

@@ -0,0 +1,7 @@
{
"SampleRate": 48000,
"SecondsToRecord": 20,
"SourcesToRecord": [],
"SaveDirectory": ".",
"Shortcut": "alt+1"
}