Skip to content

Commit

Permalink
fix bug with audio enhancement logic; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Oct 30, 2024
1 parent f09031d commit e4a78b1
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/services/storage.py
Original file line number Diff line number Diff line change
@@ -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"),
)
4 changes: 3 additions & 1 deletion src/utils/audio_synthesizer.py
Original file line number Diff line number Diff line change
@@ -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(
14 changes: 7 additions & 7 deletions src/utils/main_utils.py
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 1 addition & 4 deletions src/utils/render_audiocast.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit e4a78b1

Please sign in to comment.