File size: 809 Bytes
d23d710
 
 
 
 
 
 
 
 
 
 
 
334bc59
d23d710
334bc59
d23d710
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from pydub import AudioSegment

import streamlit as st
import plotly.graph_objs as go
import plotly.express as px
import pandas as pd
import numpy as np

@st.cache_data
def load_audio_segment(path: str, format: str) -> AudioSegment:
    return AudioSegment.from_file(path, format=format)

def plot_audio(_audio_segment: AudioSegment, title: str = None, step = 20) -> go.Figure:
    samples = _audio_segment.get_array_of_samples()
    arr = np.array(samples[::step])
    df = pd.DataFrame(arr)
    fig = px.line(df, y=0, render_mode="webgl", line_shape="linear", width=1000, height=60, title=title)
    fig.update_layout(xaxis_fixedrange=True, yaxis_fixedrange=True, yaxis_visible=False, xaxis_visible=False, hovermode=False, margin=dict(l=0, r=0, t=0, b=0))
    st.plotly_chart(fig, use_container_width=True)