diff --git a/src/services/storage.py b/src/services/storage.py index 89fae10..1580a9c 100644 --- a/src/services/storage.py +++ b/src/services/storage.py @@ -57,7 +57,7 @@ def upload_audio_to_gcs(self, tmp_audio_path: str, filename=str(uuid4())): """upload audio file to GCS""" blobname = f"{BLOB_BASE_URI}/{filename}" self.upload_to_gcs( - tmp_audio_path, + Path(tmp_audio_path), blobname, UploadItemParams(content_type="audio/mpeg"), ) diff --git a/src/utils/audio_synthesizer.py b/src/utils/audio_synthesizer.py index 6150ab2..0c47dd6 100644 --- a/src/utils/audio_synthesizer.py +++ b/src/utils/audio_synthesizer.py @@ -62,7 +62,9 @@ def enhance_audio_minimal( audio = audio.speedup(playback_speed=speed_factor) # Only normalize if significant volume differences if abs(audio.dBFS + 18.0) > 3.0: # +/- 3dB tolerance - audio = audio.normalize(target_level=-18.0) + # Calculate gain needed to reach target dBFS of -18.0 + gain_needed = -18.0 - audio.dBFS + audio = audio.apply_gain(gain_needed) # Export with high quality audio.export( diff --git a/src/utils/main_utils.py b/src/utils/main_utils.py index 91b4f7a..ad5913a 100644 --- a/src/utils/main_utils.py +++ b/src/utils/main_utils.py @@ -4,7 +4,6 @@ import streamlit as st from pydantic import BaseModel -from slugify import slugify from src.services.storage import StorageManager from src.utils.audio_manager import AudioManager @@ -25,7 +24,6 @@ class GenerateAudioCastRequest(BaseModel): class GenerateAudioCastResponse(BaseModel): uuid: str - slug: str url: str script: str source_content: str @@ -99,19 +97,21 @@ async def generate_audiocast(request: GenerateAudioCastRequest): AudioSynthesizer().enhance_audio_minimal(Path(output_file)) print(f"output_file: {output_file}") + # unique ID for the audiocast uniq_id = str(uuid.uuid4()) # TODO: Use a background service # STEP 4: Ingest audio file to a storage service (e.g., GCS, S3) with container.container(): - container.info("Storing a copy of your audiocast...") - storage_manager = StorageManager() - storage_manager.upload_audio_to_gcs(output_file, uniq_id) + try: + container.info("Storing a copy of your audiocast...") + storage_manager = StorageManager() + storage_manager.upload_audio_to_gcs(output_file, uniq_id) + except Exception as e: + print(f"Error while storing audiocast: {str(e)}") response = GenerateAudioCastResponse( - # unique ID for the audiocast uuid=uniq_id, - slug=slugify((category + summary)[:50]), url=output_file, script=audio_script, source_content=source_content, diff --git a/src/utils/render_audiocast.py b/src/utils/render_audiocast.py index f43e183..082aee4 100644 --- a/src/utils/render_audiocast.py +++ b/src/utils/render_audiocast.py @@ -9,7 +9,6 @@ class GenerateAudiocastDict(TypedDict): uuid: str - slug: str url: str script: str source_content: str @@ -34,9 +33,7 @@ def render_audiocast(): st.sidebar.subheader("Audiocast Source") st.sidebar.markdown(current_audiocast["source_content"]) - share_url = ( - f"{APP_URL}/audiocast/{current_audiocast['uuid']}/{current_audiocast['slug']}" - ) + share_url = f"{APP_URL}/audiocast/{current_audiocast['uuid']}" st.text_input("Share this audiocast:", share_url) share_col, restart_row = st.columns(2, vertical_alignment="bottom")