How to use sounddevice - 10 common examples

To help you get started, we’ve selected a few sounddevice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jim-schwoebel / voicebook / chapter_1_fundamentals / sphinx_transcibe.py View on Github external
def sync_record(filename, duration, fs, channels):
    print('recording')
    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=channels)
    sd.wait()
    sf.write(filename, myrecording, fs)
    print('done recording')
github jim-schwoebel / voicebook / chapter_2_collection / as_record.py View on Github external
def sync_record(filename, duration, fs, channels):
    print('recording')
    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=channels)
    sd.wait()
    sf.write(filename, myrecording, fs)
    print('done recording')
github jim-schwoebel / voicebook / chapter_6_visualization / text_freqplot.py View on Github external
def sync_record(filename, duration, fs, channels):
    print('recording')
    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=channels)
    sd.wait()
    sf.write(filename, myrecording, fs)
    print('done recording')
github jim-schwoebel / voicebook / chapter_6_visualization / meta_multi.py View on Github external
def record_data(filename, duration, fs, channels):
    # synchronous recording 
    print('recording')
    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=channels)
    sd.wait()
    sf.write(filename, myrecording, fs)
    print('done')
    
    return filename
github jim-schwoebel / voicebook / chapter_6_visualization / audio_path.py View on Github external
def record_data(filename, duration, fs, channels):
    # synchronous recording 
    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=channels)
    sd.wait()
    sf.write(filename, myrecording, fs)
    y, sr = librosa.load(filename)
    rmse=np.mean(librosa.feature.rmse(y)[0])
    os.remove(filename)
    
    return rmse*1000
github golabies / voice-recognition / scripts / read_data.py View on Github external
def recording(self, duration=5):
        # read data from microphone
        # duration is the length of time you want to record
        self.duration = duration
        self.voice = sd.rec(self.duration * self.fs, samplerate=self.fs, channels=self.ch, dtype='float64')
        sd.wait()
        self.voice = self.voice.T.copy()
github CorentinJ / Real-Time-Voice-Cloning / sv2tts / demo_vocoder.py View on Github external
print("Generating...")
for i in sorted(np.random.choice(len(dataset), n_samples)):
    mel, wav_gt = dataset[i]
    
    # out_gt_fpath = fileio.join(gen_path, "%s_%d_gt.wav" % (model_name, i))
    # out_pred_fpath = fileio.join(gen_path, "%s_%d_pred.wav" % (model_name, i))
    
    wav_gt = audio.unquantize_signal(wav_gt)
    if use_mu_law:
        wav_gt = audio.expand_signal(wav_gt)
    sd.wait()
    sd.play(wav_gt, 16000)
    
    wav_pred = inference.infer_waveform(mel, normalize=False)   # The dataloader already normalizes
    sd.wait()
    sd.play(wav_pred, 16000)



    # audio.save_wav(out_pred_fpath, wav_pred)
    # audio.save_wav(out_gt_fpath, wav_gt)
    print('')
github CorentinJ / Real-Time-Voice-Cloning / sv2tts / demo_sv2tts.py View on Github external
sd.wait()
            speaker_id = "user_%02d" % i
            i += 1
            speaker_embed = encoder.embed_utterance(wav_source)[None, ...]
        else:
            speaker_embed, speaker_id, wav_source = get_random_embed()
            print(speaker_id)

        # Synthesize the text with the embedding
        text = input("Text: ")
        mel = synth.my_synthesize(speaker_embed, text)
        
        wav_griffin = inv_mel_spectrogram(mel.T, hparams)
        wav_griffin = np.concatenate((wav_griffin, [0] * hparams.sample_rate))
        print("Griffin-lim:")
        sd.play(wav_griffin, 16000)
        
        wav_wavernn = vocoder.infer_waveform(mel.T)
        wav_wavernn = np.concatenate((wav_wavernn, [0] * hparams.sample_rate))
        sd.wait()
        print("\nWave-RNN:")
        sd.play(wav_wavernn, 16000)
        sd.wait()

        save_wav(wav_source, "../%s_%s.wav" % (speaker_id, "source"), 16000)
        save_wav(wav_griffin, "../%s_%s.wav" % (speaker_id, "griffin"), 16000)
        save_wav(wav_wavernn, "../%s_%s.wav" % (speaker_id, "wavernn"), 16000)
github CorentinJ / Real-Time-Voice-Cloning / tacotron2 / griffin_lim_synthesis_tool.py View on Github external
os.makedirs(out_dir, exist_ok=True)

#mel_file = os.path.join(mel_folder, mel_file)

from vlibs import fileio

# fnames = fileio.listdir('logs-two_outputs/mel-spectrograms/')
fnames = fileio.listdir('tacotron_output/eval/')
for i in range(1, len(fnames)):
    # mel_file = 'logs-two_outputs/mel-spectrograms/mel-prediction-step-110000.npy'
    mel_file = fileio.join('tacotron_output/eval/', fnames[i])
    mel_spectro = np.load(mel_file) #.transpose()
    wav = inv_mel_spectrogram(mel_spectro.T, hparams) 
    sounddevice.wait()
    print(fnames[i])
    sounddevice.play(wav, 16000)
sounddevice.wait()
quit()

save_wav(wav, os.path.join(out_dir, 'test_mel_{}.wav'.format(mel_file.replace('/', '_').replace('\\', '_').replace('.npy', ''))),
        sr=hparams.sample_rate)


# In[3]:


from tacotron.utils.plot import *

plot_spectrogram(mel_spectro, path=os.path.join(out_dir, 'test_mel_{}.png'.format(mel_file.replace('/', '_').replace('\\', '_').replace('.npy', ''))))


# In[4]:
github BciPy / BciPy / bcipy / helpers / demo / demo_sound_card.py View on Github external
import argparse
import logging
log = logging.getLogger(__name__)
# To use, cd into helpers directory, run >> python demo/sound_card_demo.py "filename"
# Example: python demo/sound_card_demo.py "../static/sounds/chime.wav"

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("filename", help="audio file to be played back")
parser.add_argument("-d", "--device", type=int, help="device ID")
args = parser.parse_args()

try:
    import sounddevice as sd
    import soundfile as sf
    devices = sd.query_devices()
    print(devices)
    data, fs = sf.read(args.filename, dtype='float32')
    sd.play(data, fs, device=args.device, blocking=True)
    status = sd.get_status()
    if status:
        log.warning(str(status))
except BaseException as e:
    # This avoids printing the traceback, especially if Ctrl-C is used.
    raise SystemExit(str(e))