當前位置: 首頁>>代碼示例>>Python>>正文


Python sounddevice.wait方法代碼示例

本文整理匯總了Python中sounddevice.wait方法的典型用法代碼示例。如果您正苦於以下問題:Python sounddevice.wait方法的具體用法?Python sounddevice.wait怎麽用?Python sounddevice.wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sounddevice的用法示例。


在下文中一共展示了sounddevice.wait方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: record_sound

# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import wait [as 別名]
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 
開發者ID:a-n-rose,項目名稱:Build-CNN-or-LSTM-or-CNNLSTM-with-speech-features,代碼行數:8,代碼來源:implement_model.py

示例2: extract_features

# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import wait [as 別名]
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 
開發者ID:GianlucaPaolocci,項目名稱:Sound-classification-on-Raspberry-Pi-with-Tensorflow,代碼行數:15,代碼來源:classiPi.py

示例3: play

# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import wait [as 別名]
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() 
開發者ID:kalliope-project,項目名稱:kalliope,代碼行數:9,代碼來源:sounddeviceplayer.py

示例4: play_one_audio_file

# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import wait [as 別名]
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() 
開發者ID:sassoftware,項目名稱:python-dlpy,代碼行數:42,代碼來源:speech_utils.py


注:本文中的sounddevice.wait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。