Skip to content

Commit

Permalink
Fix for missing voice name in adjusted .srt file
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei committed Jan 30, 2025
1 parent e32013e commit a483267
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
7 changes: 7 additions & 0 deletions adobe_premiere/extensions/SailvuePanel/jsx/PPRO/Premiere.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,14 @@ $._PPP_={

for(var j =0 ; j < clipList.length; j++) {
var clip = clipList[j];
// If clip has extension .srt skip it
if (clip.name.toLowerCase().indexOf('.srt') > 0) {
continue;
}

$._PPP_.updateEventPanel("Checking Clip " + clip.name);
var markers = clip.getMarkers();
$._PPP_.updateEventPanel("Clip " + clip.name + " has " + markers.numMarkers + " markers");

// Get list of sailvue markers in this clip
var sailvueMarkers = [];
Expand Down
2 changes: 2 additions & 0 deletions voiceover/elevenlabs/args/3bf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--srt-name=/Users/sergei/SailingVideos/2025-3BF/60-VOICEOVER/02-WHOLE-MOVIE-TAKE-1/03-3bf.srt
--output-dir=/Users/sergei/SailingVideos/2025-3BF/60-VOICEOVER/02-WHOLE-MOVIE-TAKE-1
2 changes: 2 additions & 0 deletions voiceover/elevenlabs/args/yra-dh-mw-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--srt-name=/Users/sergei/SailingVideos/2025-01-05-DH-MW-3/60-VOICEOVER/02-FLAT-UNCUT.srt
--output-dir=/Users/sergei/SailingVideos/2025-01-05-DH-MW-3/60-VOICEOVER/
30 changes: 17 additions & 13 deletions voiceover/elevenlabs/make_voiceover.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_voice_id(require_voice_name, text, default_voice_id):
print('No speaker found in the text')
return text, None

return text, default_voice_id
return text, default_voice_id, speaker


def make_voiceover_file(number, text, api_key, voice_id, output_dir):
Expand All @@ -52,14 +52,15 @@ def make_voiceover_file(number, text, api_key, voice_id, output_dir):
file_name += '-' + text_hash
file_name = output_dir + os.sep + f'{number:03d}-' + file_name + '.mp3'

# Check if the file with the same hash already exists in the output directory
# Check if MP3 file with the same hash already exists in the output directory
files = os.listdir(output_dir)
for file in files:
t = file.split('-')
if len(t) > 1 and t[2] == text_hash + '.mp3':
current_name = output_dir + os.sep + file
print(f'File {current_name} for this text already exists, skipping ...')
return current_name
if file.lower().endswith('.mp3'):
t = file.split('-')
if len(t) > 1 and t[2] == text_hash + '.mp3':
current_name = output_dir + os.sep + file
print(f'File {current_name} for this text already exists, skipping ...')
return current_name

# Make the voiceover using eleven labs API
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
Expand Down Expand Up @@ -107,7 +108,7 @@ def decode_time(line):
return time_from, time_to


def make_chapter(number, start_time, end_time, text, file_name):
def make_chapter(number, start_time, end_time, text, file_name, speaker):
audio = MP3(file_name)
mp3_duration_sec = timedelta(seconds=audio.info.length)
text_hash = os.path.splitext(os.path.basename(file_name))[0].split('-')[2]
Expand All @@ -119,6 +120,7 @@ def make_chapter(number, start_time, end_time, text, file_name):
'mp3_duration_sec': mp3_duration_sec,
'hash': text_hash,
'file_name': file_name,
'speaker': speaker
}


Expand Down Expand Up @@ -162,9 +164,9 @@ def make_voiceover(param):
elif line == '':
print(f'Chapter {number}:\n[{text}]')
# Find the name of the speaker denoted as [name]: in the text
text, voice_id = get_voice_id(require_voice_name, text, default_voice_id)
text, voice_id, speaker = get_voice_id(require_voice_name, text, default_voice_id)
file_name = make_voiceover_file(number, text, key, voice_id, output_dir)
chapters.append(make_chapter(number, start_time, end_time, text, file_name))
chapters.append(make_chapter(number, start_time, end_time, text, file_name, speaker))
got_number = False
got_time = False
text = ''
Expand All @@ -174,9 +176,9 @@ def make_voiceover(param):
# Process the last chapter
if text != '':
print(f'Chapter {number}:\n[{text}]')
text, voice_id = get_voice_id(require_voice_name, text, default_voice_id)
text, voice_id, speaker = get_voice_id(require_voice_name, text, default_voice_id)
file_name = make_voiceover_file(number, text, key, voice_id, output_dir)
chapters.append(make_chapter(number, start_time, end_time, text, file_name))
chapters.append(make_chapter(number, start_time, end_time, text, file_name, speaker))

adjust_time_stamps(chapters)

Expand All @@ -188,7 +190,9 @@ def make_voiceover(param):
srt_output_file.write(f"{chapter['number']}\n")
srt_output_file.write(
f"{chapter['start_time'].strftime('%H:%M:%S,000')} --> {chapter['end_time'].strftime('%H:%M:%S,000')}\n")
srt_output_file.write(f"{chapter['text']}\n")
if chapter['speaker'] is not None:
srt_output_file.write(f"[{chapter['speaker']}]: ")
srt_output_file.write(f"{chapter['text']}\n\n")

# Make sure that chapter number in file name matches actual chapter number
for chapter in chapters:
Expand Down

0 comments on commit a483267

Please sign in to comment.