Python sounddevice.wait() Examples
The following are 4
code examples of sounddevice.wait().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sounddevice
, or try the search function
.
Example #1
Source File: classiPi.py From Sound-classification-on-Raspberry-Pi-with-Tensorflow with MIT License | 6 votes |
def extract_features(): X = sounddevice.rec(int(duration * sample_rate), samplerate=sample_rate, channels=1) sounddevice.wait() X= np.squeeze(X) stft = np.abs(librosa.stft(X)) mfccs = np.array(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=8).T) chroma = np.array(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T) mel = np.array(librosa.feature.melspectrogram(X, sr=sample_rate).T) contrast = np.array(librosa.feature.spectral_contrast(S=stft, sr=sample_rate).T) tonnetz = np.array(librosa.feature.tonnetz(y=librosa.effects.harmonic(X), sr=sample_rate).T) ext_features = np.hstack([mfccs,chroma,mel,contrast,tonnetz]) features = np.vstack([features,ext_features]) return features
Example #2
Source File: implement_model.py From Build-CNN-or-LSTM-or-CNNLSTM-with-speech-features with MIT License | 5 votes |
def record_sound(sec,message): sr = 16000 print(message+" for {} seconds..".format(sec)) sound = sd.rec(int(sec*sr),samplerate=sr,channels=1) sd.wait() return sound, sr
Example #3
Source File: sounddeviceplayer.py From kalliope with GNU General Public License v3.0 | 5 votes |
def play(self, file_path): if self.convert: self.convert_mp3_to_wav(file_path_mp3=file_path) data, fs = sf.read(file_path) sd.play(data, fs) sd.wait()
Example #4
Source File: speech_utils.py From python-dlpy with Apache License 2.0 | 5 votes |
def play_one_audio_file(local_audio_file): ''' Play a local audio file using soundfile and sounddevice. Parameters ---------- local_audio_file : string Local location to the audio file to be played. When it is a directory, a file will be randomly chosen. Returns ------- None Raises ------ DLPyError If anything goes wrong, it complains and prints the appropriate message. ''' try: import soundfile as sf import sounddevice as sd except (ModuleNotFoundError, ImportError): raise DLPyError('cannot import soundfile or sounddevice') if os.path.isdir(local_audio_file): local_audio_file_real = random_file_from_dir(local_audio_file) else: local_audio_file_real = local_audio_file print('File location: {}'.format(local_audio_file_real)) data, sampling_rate = sf.read(local_audio_file_real) print('Frequency [Hz]: {}'.format(sampling_rate)) print('Duration [s]: {}'.format(data.shape[0]/sampling_rate)) sd.play(data, sampling_rate) sd.wait()