Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stop_recording():
global waveform
actual_time = time.time()-start_time
sd.stop()
samples = min(int(actual_time*sd.default.samplerate), len(waveform))
waveform = waveform[0:samples, 0]
sd.play(waveform)
sd.wait()
get_axes().clear()
spectrum, freqs, t, im = get_axes().specgram(waveform,
Fs=sd.default.samplerate)
redraw()
return np.transpose(spectrum)
def _get_stream_parameters(kind, device, channels, dtype, latency,
extra_settings, samplerate):
"""Get parameters for one direction (input or output) of a stream."""
assert kind in ('input', 'output')
if device is None:
device = default.device[kind]
if channels is None:
channels = default.channels[kind]
if dtype is None:
dtype = default.dtype[kind]
if latency is None:
latency = default.latency[kind]
if extra_settings is None:
extra_settings = default.extra_settings[kind]
if samplerate is None:
samplerate = default.samplerate
device = _get_device_id(device, kind, raise_on_error=True)
info = query_devices(device)
if channels is None:
channels = info['max_' + kind + '_channels']
try:
# If NumPy is available, get canonical dtype name
dtype = _sys.modules['numpy'].dtype(dtype).name
except Exception:
pass # NumPy not available or invalid dtype (e.g. 'int24') or ...
try:
sampleformat = _sampleformats[dtype]
except KeyError:
raise ValueError('Invalid ' + kind + ' sample format')
samplesize = _check(_lib.Pa_GetSampleSize(sampleformat))
if latency in ('low', 'high'):
def __repr__(self):
idev = _get_device_id(default.device['input'], 'input')
odev = _get_device_id(default.device['output'], 'output')
digits = len(str(_lib.Pa_GetDeviceCount() - 1))
hostapi_names = [hostapi['name'] for hostapi in query_hostapis()]
text = '\n'.join(
u'{mark} {idx:{dig}} {name}, {ha} ({ins} in, {outs} out)'.format(
mark=(' ', '>', '<', '*')[(idx == idev) + 2 * (idx == odev)],
idx=idx,
dig=digits,
name=info['name'],
ha=hostapi_names[info['hostapi']],
ins=info['max_input_channels'],
outs=info['max_output_channels'])
for idx, info in enumerate(self))
return text
researchers, enterprises, and/or independent developers.
If you would like to work with us let us know @ js@neurolex.co.
================================================
## MIC_CHECK.PY ##
================================================
Mic_check.py
Check available microphones for recording and playback.
'''
import sounddevice as sd
mics=sd.query_devices()
default_devices=sd.default.device
default_input=default_devices[0]
default_output=default_devices[1]
# prints all available devices
for i in range(len(mics)):
print(mics[i])
# can set default device easily with
sd.default.device = 0
compactsix_server.audio)
file_counter += 1
# then manually wait for the pyramic to finish
pause()
time_counter = 0.
# restart compactsix recording
compactsix_server = AudioGetter("192.168.2.11:8888", chunk_length+5, fs=fs_in, channels=6)
compactsix_server.start()
# Play both signals on all pairs
s1 = signals[0]
s2 = signals[1]
for ch1 in range(sd.default.channels[1]):
for ch2 in range(ch1+1, sd.default.channels[1]):
if skip_counter < skip:
skip_counter += 1
continue
signal[:s1.shape[0],ch1] = s1
signal[:s2.shape[0],ch2] = s2
sd.play(signal, fs_out, blocking=True)
signal[:,ch1] = 0.
signal[:,ch2] = 0.
time.sleep(T_sleep)
time_counter += length/fs_out + T_sleep
def __init__(self, dejavu):
super(MicrophoneRecognizer, self).__init__(dejavu)
sd.default.samplerate = MicrophoneRecognizer.default_samplerate
sd.default.channels = MicrophoneRecognizer.default_channels
sd.default.dtype = MicrophoneRecognizer.default_format
self.data = [[], []]
self.recorded = False