cc_vad / toolbox /torchaudio /utils /visualization.py
HoneyTian's picture
update
19f8ea7
raw
history blame contribute delete
897 Bytes
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from typing import List
import matplotlib.pyplot as plt
import numpy as np
def process_speech_probs(signal: np.ndarray, speech_probs: List[float], frame_step: int) -> np.ndarray:
speech_probs_ = list()
for p in speech_probs[1:]:
speech_probs_.extend([p] * frame_step)
pad = (signal.shape[0] - len(speech_probs_))
speech_probs_ = speech_probs_ + [0.0] * pad
speech_probs_ = np.array(speech_probs_, dtype=np.float32)
if len(speech_probs_) != len(signal):
raise AssertionError
return speech_probs_
def make_visualization(signal: np.ndarray, speech_probs, sample_rate: int):
time = np.arange(0, len(signal)) / sample_rate
plt.figure(figsize=(12, 5))
plt.plot(time, signal, color='b')
plt.plot(time, speech_probs, color='gray')
plt.show()
return
if __name__ == "__main__":
pass