How to use the sounddevice.wait function in sounddevice

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 PiotrSobczak / speech-emotion-recognition / ser / live_demo.py View on Github external
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-l", "--linguistic_model", type=str, required=True)
    parser.add_argument("-a", "--acoustic_model", type=str, required=True)
    parser.add_argument("-e", "--ensemble_model", type=str, required=True)
    parser.add_argument("-d", "--deepspeech", type=str, required=True)
    parser.add_argument("-s", "--seconds", type=int, default=DURATION_IN_SEC)
    args = parser.parse_args()
    
    assert isfile(args.ensemble_model), "acoustic_model weights file does not exist"
    assert isfile(args.ensemble_model.replace(".torch", ".json")), "acoustic_model config file does not exist"
    assert isdir(args.deepspeech)
    
    print("Starting recording for {} seconds...".format(args.seconds))
    myrecording = sd.rec(int(args.seconds * SAMPLE_RATE), samplerate=SAMPLE_RATE, channels=1, dtype=np.int16)
    sd.wait()  # Wait until recording is finished
    print("Recording finished")
    
    write(TMP_FILENAME, SAMPLE_RATE, myrecording)  # Save as WAV file
    
    from deepspeech_generator import speech_to_text
    transcription = speech_to_text(join(args.deepspeech, "output_graph.pbmm"), join(args.deepspeech, "alphabet.txt"), join(args.deepspeech, "lm.binary"), join(args.deepspeech, "trie"), TMP_FILENAME)
    print(transcription)
    
    """Converting model to specified hardware and format"""
    acoustic_cfg_json = json.load(open(args.acoustic_model.replace(".torch", ".json"), "r"))
    acoustic_cfg = AcousticSpectrogramConfig.from_json(acoustic_cfg_json)
    
    acoustic_model = CNN(acoustic_cfg)
    acoustic_model.float().to("cpu")
    
    try:
github CorentinJ / Real-Time-Voice-Cloning / sv2tts / demo_vocoder.py View on Github external
n_samples = 5
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 jim-schwoebel / voicebook / chapter_1_fundamentals / sync_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_7_design / transcribe_custom.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 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 jim-schwoebel / voicebook / chapter_2_collection / ps_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 / 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 / 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 CorentinJ / Real-Time-Voice-Cloning / toolbox / ui.py View on Github external
self.log("Recording %d seconds of audio" % duration)
        sd.stop()
        try:
            wav = sd.rec(duration * sample_rate, sample_rate, 1)
        except Exception as e:
            print(e)
            self.log("Could not record anything. Is your recording device enabled?")
            self.log("Your device must be connected before you start the toolbox.")
            return None
        
        for i in np.arange(0, duration, 0.1):
            self.set_loading(i, duration)
            sleep(0.1)
        self.set_loading(duration, duration)
        sd.wait()
        
        self.log("Done recording.")
        self.record_button.setText("Record one")
        self.record_button.setDisabled(False)
        
        return wav.squeeze()