Skip to content

Commit

Permalink
put waveform viz in an expander
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 1, 2024
1 parent b5e7230 commit ec95a25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 8 additions & 4 deletions pages/audiocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ async def render_audiocast_page():
with st.spinner("Loading audiocast..."):
audiocast = get_audiocast(session_id)

# Audio player
st.audio(audiocast["url"])

# Create placeholder for visualization
if audiocast["url"]:
with st.expander("Show Waveform Visualization"):
viz = st.empty()
with viz.container():
try:
Expand All @@ -42,9 +45,6 @@ async def render_audiocast_page():
except Exception as e:
st.error(f"Error rendering waveform: {str(e)}")

# Audio player
st.audio(audiocast["url"])

# Transcript
with st.expander("Show Transcript"):
st.markdown(parse_ai_script(audiocast["script"]))
Expand All @@ -67,6 +67,10 @@ async def render_audiocast_page():
if st.button("Create your Audiocast", use_container_width=True):
navigate_to_home()

if st.session_state.get("show_copy_success", False):
st.session_state.show_copy_succes = False
st.success("Share link copied successfully!", icon="✅")

if audiocast["created_at"]:
st.markdown(f"> Created: {audiocast["created_at"]}")

Expand Down
13 changes: 13 additions & 0 deletions src/utils/render_audiocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from src.env_var import APP_URL
from src.utils.session_state import reset_session
from src.utils.waveform_utils import download_waveform_video, render_waveform


class GenerateAudiocastDict(TypedDict):
Expand All @@ -31,6 +32,18 @@ def render_audiocast(session_id: str):
# Audio player
st.audio(current_audiocast["url"])

# Create placeholder for visualization
with st.expander("Show Waveform Visualization"):
viz = st.empty()
with viz.container():
try:
video_path = render_waveform(session_id, current_audiocast["url"])
if video_path:
# Download video
download_waveform_video(str(video_path))
except Exception as e:
st.error(f"Error rendering waveform: {str(e)}")

# Transcript
with st.expander("Show Transcript"):
st.markdown(parse_ai_script(current_audiocast["script"]))
Expand Down
5 changes: 3 additions & 2 deletions src/utils/waveform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def generate_waveform_video(output_path: Path, audio_path: str) -> Path:
bars=60,
speed=4,
time=0.4,
rate=60,
size=(200, 200),
# rate=60,
size=(120, 68),
fg_color=(0.0, 1.0, 0.6), # Bright green. Try 0.2 0.2 0.2 for dark green
bg_color=(0.05, 0.05, 0.05), # Near black
)
Expand Down Expand Up @@ -65,4 +65,5 @@ def download_waveform_video(video_path: str):
data=f,
file_name="audio_visualization.mp4",
mime="video/mp4",
use_container_width=True
)

0 comments on commit ec95a25

Please sign in to comment.