Skip to content

Commit

Permalink
Add silent seconds between 2 combining audio
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin committed Sep 22, 2024
1 parent 35027e2 commit 461d062
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/routers/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ async def _post_process_memory(memory: Memory):

# merge
merge_file_path = f"_temp/{memory.id}_{uuid.uuid4()}_be"
merge_wav_files(merge_file_path, [previous_file_path, file_path])
nearest_timer_start = processing_memory.timer_starts[-2]
merge_wav_files(merge_file_path, [previous_file_path, file_path], [math.ceil(timer_start-nearest_timer_start), 0])

# clean
os.remove(previous_file_path)
Expand Down
8 changes: 5 additions & 3 deletions backend/utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
from pyogg import OpusDecoder
from pydub import AudioSegment

def merge_wav_files(dest_file_path: str, source_files: [str]):
def merge_wav_files(dest_file_path: str, source_files: [str], silent_seconds: [int]):
if len(source_files) == 0 or not dest_file_path:
return

combined_sounds = AudioSegment.empty()
for file_path in source_files:
for i in range(len(source_files)):
file_path = source_files[i]
sound = AudioSegment.from_wav(file_path)
combined_sounds = combined_sounds + sound
silent_sec = silent_seconds[i]
combined_sounds = combined_sounds + sound + AudioSegment.silent(duration=silent_sec)
combined_sounds.export(dest_file_path, format="wav")


Expand Down

0 comments on commit 461d062

Please sign in to comment.