Beispiel #1
0
def getAudioArray(audio: AudioClip) -> np.ndarray:
    """
        convert from AudioClip to numpy array
        
        argument
            - audio : AudioClip class
            
        return
            - _audio_np_mono : only 1 dimention audio data
    """

    _audio_np = audio.to_soundarray()

    if _audio_np.ndim == 2:
        _audio_np_mono = np.mean(_audio_np, 1)
    elif _audio_np.ndim == 1:
        _audio_np_mono = _audio_np
    else:
        raise Exception('audio array dimension is only 1 or 2')

    assert _audio_np_mono.ndim > 0, "Audio data is empty"

    return _audio_np_mono
Beispiel #2
0
def audio_to_frames(audio: AudioClip):
    return audio.to_soundarray()