chompionsawelo commited on
Commit
581b947
·
1 Parent(s): 795974e

minor fixes

Browse files
Files changed (7) hide show
  1. adjust.py +9 -8
  2. app.py +1 -1
  3. diarization.py +4 -4
  4. file_name.py +8 -41
  5. set_up.py +10 -17
  6. transcribe.py +2 -2
  7. utils.py +13 -13
adjust.py CHANGED
@@ -101,31 +101,32 @@ def get_speakers_previous(to_name):
101
  return get_current()
102
 
103
 
104
- def start_adjust(input_file, to_name, progress=gr.Progress()):
105
  change_name(to_name)
106
 
107
  # Replacing texts
108
  progress(0.4, desc=ui_lang["progress_adjust_speaker"])
109
- transcribe_txt_list, subtitle_txt_list = utils.read_transcribe_subtitle_file(
110
- False)
111
  modified_transcribe = replace_text(transcribe_txt_list)
112
  modified_subtitle = replace_text(subtitle_txt_list)
113
  utils.write_transcribe_subtitle_file(
114
- modified_transcribe, modified_subtitle, True)
115
 
116
  # Adding subtitle to video
117
  progress(0.8, desc=ui_lang["progress_add_subtitle"])
118
  add_subtitle_to_video(
119
- input_file, get_subtitle_adjusted_file(), get_video_subtitle_file(), start_time_for_adjustment, end_time_for_adjustment)
120
 
121
  # Return video file link, transcribe string, transcribe.txt, subtitle.txt
122
- transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(True)
 
123
  print(line for line in transcribe_txt_list)
124
  transcribe_txt = "\n".join(transcribe_txt_list)
125
  return [
126
- get_video_subtitle_file(),
127
  transcribe_txt,
128
- [get_transcribe_adjusted_file(), get_subtitle_adjusted_file()]
129
  ]
130
 
131
 
 
101
  return get_current()
102
 
103
 
104
+ def start_adjust(input_file, to_name, start_time, end_time, progress=gr.Progress()):
105
  change_name(to_name)
106
 
107
  # Replacing texts
108
  progress(0.4, desc=ui_lang["progress_adjust_speaker"])
109
+ transcribe_txt_list, subtitle_txt_list = utils.read_transcribe_subtitle_file(input_file,
110
+ False)
111
  modified_transcribe = replace_text(transcribe_txt_list)
112
  modified_subtitle = replace_text(subtitle_txt_list)
113
  utils.write_transcribe_subtitle_file(
114
+ input_file, modified_transcribe, modified_subtitle, True)
115
 
116
  # Adding subtitle to video
117
  progress(0.8, desc=ui_lang["progress_add_subtitle"])
118
  add_subtitle_to_video(
119
+ input_file, subtitle_adjusted_file, video_subtitle_file, start_time, end_time)
120
 
121
  # Return video file link, transcribe string, transcribe.txt, subtitle.txt
122
+ transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(
123
+ input_file, True)
124
  print(line for line in transcribe_txt_list)
125
  transcribe_txt = "\n".join(transcribe_txt_list)
126
  return [
127
+ video_subtitle_file,
128
  transcribe_txt,
129
+ [transcribe_adjusted_file, subtitle_adjusted_file]
130
  ]
131
 
132
 
app.py CHANGED
@@ -52,7 +52,7 @@ with gr.Blocks() as demo:
52
  adjust_speaker, adjust_audio])
53
 
54
  adjust_button.render()
55
- adjust_button.click(start_adjust, inputs=[input_video, adjust_speaker], outputs=[
56
  output_video, output_transcribe, output_file])
57
 
58
  with gr.Accordion("Copyright"):
 
52
  adjust_speaker, adjust_audio])
53
 
54
  adjust_button.render()
55
+ adjust_button.click(start_adjust, inputs=[input_video, adjust_speaker, start_time, end_time,], outputs=[
56
  output_video, output_transcribe, output_file])
57
 
58
  with gr.Accordion("Copyright"):
diarization.py CHANGED
@@ -36,7 +36,7 @@ def start_diarization(input_file):
36
  print(
37
  f"start={turn.start:.3f}s stop={turn.end:.3f}s speaker_{speaker}")
38
 
39
- save_groups_json(sample_groups, speaker_groups)
40
  audio_segmentation(input_file, speaker_groups)
41
  print(str(speaker_groups))
42
  return str(speaker_groups)
@@ -51,8 +51,8 @@ def audio_segmentation(input_file, speaker_groups_dict):
51
  print(f"group {speaker}: {time[0]*1000}--{time[1]*1000}")
52
 
53
 
54
- def save_groups_json(sample_groups_list: list, speaker_groups_dict: dict):
55
- with open(get_sample_groups_json(), "w", encoding="utf-8") as json_file_sample:
56
  json.dump(sample_groups_list, json_file_sample)
57
- with open(get_speaker_groups_json(), "w", encoding="utf-8") as json_file_speaker:
58
  json.dump(speaker_groups_dict, json_file_speaker)
 
36
  print(
37
  f"start={turn.start:.3f}s stop={turn.end:.3f}s speaker_{speaker}")
38
 
39
+ save_groups_json(input_file, sample_groups, speaker_groups)
40
  audio_segmentation(input_file, speaker_groups)
41
  print(str(speaker_groups))
42
  return str(speaker_groups)
 
51
  print(f"group {speaker}: {time[0]*1000}--{time[1]*1000}")
52
 
53
 
54
+ def save_groups_json(input_file, sample_groups_list: list, speaker_groups_dict: dict):
55
+ with open(sample_groups_json, "w", encoding="utf-8") as json_file_sample:
56
  json.dump(sample_groups_list, json_file_sample)
57
+ with open(speaker_groups_json, "w", encoding="utf-8") as json_file_speaker:
58
  json.dump(speaker_groups_dict, json_file_speaker)
file_name.py CHANGED
@@ -3,44 +3,11 @@ import os
3
 
4
  current_working_directory = os.getcwd()
5
 
6
- current_input_file = ""
7
-
8
-
9
- def get_title():
10
- return os.path.basename(current_input_file)
11
-
12
-
13
- def get_audio_file():
14
- return f"{current_working_directory}/input_{get_title()}.wav"
15
-
16
-
17
- def get_transcribe_file():
18
- return f"{current_working_directory}/transcribe_{get_title()}.txt"
19
-
20
-
21
- def get_subtitle_file():
22
- return f"{current_working_directory}/subtitle_{get_title()}.srt"
23
-
24
-
25
- def get_transcribe_adjusted_file():
26
- return f"{current_working_directory}/transcribe_adjusted_{get_title()}.txt"
27
-
28
-
29
- def get_subtitle_adjusted_file():
30
- return f"{current_working_directory}/subtitle_adjusted_{get_title()}.srt"
31
-
32
-
33
- def get_video_subtitle_file():
34
- return f"{current_working_directory}/output_{get_title()}.mp4"
35
-
36
-
37
- def get_sample_groups_json():
38
- return f"{current_working_directory}/sample_groups_{get_title()}.json"
39
-
40
-
41
- def get_speaker_groups_json():
42
- return f"{current_working_directory}/speaker_groups_{get_title()}.json"
43
-
44
-
45
- start_time_for_adjustment = "00:00:00"
46
- end_time_for_adjustment = "01:00:00"
 
3
 
4
  current_working_directory = os.getcwd()
5
 
6
+ audio_file = f"{current_working_directory}/input.wav"
7
+ transcribe_file = f"{current_working_directory}/transcribe.txt"
8
+ subtitle_file = f"{current_working_directory}/subtitle.srt"
9
+ transcribe_adjusted_file = f"{current_working_directory}/transcribe_adjusted.txt"
10
+ subtitle_adjusted_file = f"{current_working_directory}/subtitle_adjusted.srt"
11
+ video_subtitle_file = f"{current_working_directory}/output.mp4"
12
+ sample_groups_json = f"{current_working_directory}/sample_groups.json"
13
+ speaker_groups_json = f"{current_working_directory}/speaker_groups.json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
set_up.py CHANGED
@@ -28,42 +28,35 @@ def prepare_input(input_file, start_time, end_time, lang, model_size, use_summar
28
  gr.Warning(ui_lang["model_dropdown_warning"])
29
  return [None, None, [None, None]]
30
 
31
- global current_input_file
32
- current_input_file = input_file
33
- global start_time_for_adjustment
34
- start_time_for_adjustment = start_time
35
- global end_time_for_adjustment
36
- end_time_for_adjustment = end_time
37
-
38
  print(f"SOURCE: {input_file}")
39
- print(f"VIDEO FILE: {current_input_file}")
40
- print(f"AUDIO FILE: {get_audio_file()}")
41
 
42
  # Convert video to audio
43
  progress(0.2, desc=ui_lang["progress_preparing_video"])
44
  convert_video_to_audio(
45
- input_file, get_audio_file(), start_time, end_time)
46
 
47
  # Start diarization
48
  progress(0.4, desc=ui_lang["progress_acquiring_diarization"])
49
- start_diarization(get_audio_file())
50
 
51
  # Start transcribing
52
  progress(0.6, desc=ui_lang["progress_transcribing_audio"])
53
- start_transcribe(lang, model_size, progress)
54
 
55
  # Add subtitle to video
56
  progress(0.8, desc=ui_lang["progress_add_subtitle"])
57
- add_subtitle_to_video(input_file, get_subtitle_file(),
58
- get_video_subtitle_file(), start_time, end_time)
59
 
60
  # Return video file link, transcribe string, transcribe.txt, subtitle.txt
61
- transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(False)
 
62
  transcribe_txt = "\n".join(transcribe_txt_list)
63
  return [
64
- get_video_subtitle_file(),
65
  transcribe_txt,
66
- [get_transcribe_file(), get_subtitle_file()]
67
  ]
68
 
69
 
 
28
  gr.Warning(ui_lang["model_dropdown_warning"])
29
  return [None, None, [None, None]]
30
 
 
 
 
 
 
 
 
31
  print(f"SOURCE: {input_file}")
32
+ print(f"AUDIO FILE: {audio_file}")
 
33
 
34
  # Convert video to audio
35
  progress(0.2, desc=ui_lang["progress_preparing_video"])
36
  convert_video_to_audio(
37
+ input_file, audio_file, start_time, end_time)
38
 
39
  # Start diarization
40
  progress(0.4, desc=ui_lang["progress_acquiring_diarization"])
41
+ start_diarization(audio_file)
42
 
43
  # Start transcribing
44
  progress(0.6, desc=ui_lang["progress_transcribing_audio"])
45
+ start_transcribe(input_file, lang, model_size, progress)
46
 
47
  # Add subtitle to video
48
  progress(0.8, desc=ui_lang["progress_add_subtitle"])
49
+ add_subtitle_to_video(input_file, subtitle_file,
50
+ video_subtitle_file, start_time, end_time)
51
 
52
  # Return video file link, transcribe string, transcribe.txt, subtitle.txt
53
+ transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(
54
+ input_file, False)
55
  transcribe_txt = "\n".join(transcribe_txt_list)
56
  return [
57
+ video_subtitle_file,
58
  transcribe_txt,
59
+ [transcribe_file, subtitle_file]
60
  ]
61
 
62
 
transcribe.py CHANGED
@@ -12,7 +12,7 @@ model_lang_list = ['en', 'id', None]
12
  model_size = ["tiny", "base", "small", "medium", "large"]
13
 
14
 
15
- def start_transcribe(lang_choice: int, model_size_choice: int, progress):
16
 
17
  print(
18
  f"Starting transcribing with model size {model_size[model_size_choice]} for language {model_lang_list[lang_choice]}")
@@ -49,7 +49,7 @@ def start_transcribe(lang_choice: int, model_size_choice: int, progress):
49
  transcribe_txt_list.append(f"[{name}] {speaker_txt}\n")
50
 
51
  utils.write_transcribe_subtitle_file(
52
- transcribe_txt_list, subtitle_txt_list, False)
53
 
54
 
55
  def time_str(t):
 
12
  model_size = ["tiny", "base", "small", "medium", "large"]
13
 
14
 
15
+ def start_transcribe(input_file, lang_choice: int, model_size_choice: int, progress):
16
 
17
  print(
18
  f"Starting transcribing with model size {model_size[model_size_choice]} for language {model_lang_list[lang_choice]}")
 
49
  transcribe_txt_list.append(f"[{name}] {speaker_txt}\n")
50
 
51
  utils.write_transcribe_subtitle_file(
52
+ input_file, transcribe_txt_list, subtitle_txt_list, False)
53
 
54
 
55
  def time_str(t):
utils.py CHANGED
@@ -4,23 +4,23 @@ import os
4
 
5
 
6
  def load_groups_json():
7
- if not os.path.exists(get_sample_groups_json()) or not os.path.exists(get_speaker_groups_json()):
8
  print("JSON file doesn't exist")
9
  return [], {}
10
 
11
- with open(get_sample_groups_json(), "r", encoding="utf-8") as json_file_sample:
12
  sample_groups_list: list = json.load(json_file_sample)
13
- with open(get_speaker_groups_json(), "r", encoding="utf-8") as json_file_speaker:
14
  speaker_groups_dict: dict = json.load(json_file_speaker)
15
  return sample_groups_list, speaker_groups_dict
16
 
17
 
18
- def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list: list, adjustment: bool):
19
- transcribe = get_transcribe_file()
20
- subtitle = get_subtitle_file()
21
  if adjustment:
22
- transcribe = get_transcribe_adjusted_file()
23
- subtitle = get_subtitle_adjusted_file()
24
 
25
  with open(transcribe, "w", encoding="utf-8") as file:
26
  file.writelines(transcribe_txt_list)
@@ -28,12 +28,12 @@ def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list:
28
  file.writelines(subtitle_txt_list)
29
 
30
 
31
- def read_transcribe_subtitle_file(adjustment: bool):
32
- transcribe = get_transcribe_file()
33
- subtitle = get_subtitle_file()
34
  if adjustment:
35
- transcribe = get_transcribe_adjusted_file()
36
- subtitle = get_subtitle_adjusted_file()
37
 
38
  if not os.path.exists(transcribe) or not os.path.exists(subtitle):
39
  print("Transcribe or subtitle file doesn't exist")
 
4
 
5
 
6
  def load_groups_json():
7
+ if not os.path.exists(sample_groups_json) or not os.path.exists(speaker_groups_json):
8
  print("JSON file doesn't exist")
9
  return [], {}
10
 
11
+ with open(sample_groups_json, "r", encoding="utf-8") as json_file_sample:
12
  sample_groups_list: list = json.load(json_file_sample)
13
+ with open(speaker_groups_json, "r", encoding="utf-8") as json_file_speaker:
14
  speaker_groups_dict: dict = json.load(json_file_speaker)
15
  return sample_groups_list, speaker_groups_dict
16
 
17
 
18
+ def write_transcribe_subtitle_file(input_file, transcribe_txt_list: list, subtitle_txt_list: list, adjustment: bool):
19
+ transcribe = transcribe_file
20
+ subtitle = subtitle_file
21
  if adjustment:
22
+ transcribe = transcribe_adjusted_file
23
+ subtitle = subtitle_adjusted_file
24
 
25
  with open(transcribe, "w", encoding="utf-8") as file:
26
  file.writelines(transcribe_txt_list)
 
28
  file.writelines(subtitle_txt_list)
29
 
30
 
31
+ def read_transcribe_subtitle_file(input_file, adjustment: bool):
32
+ transcribe = transcribe_file
33
+ subtitle = subtitle_file
34
  if adjustment:
35
+ transcribe = transcribe_adjusted_file
36
+ subtitle = subtitle_adjusted_file
37
 
38
  if not os.path.exists(transcribe) or not os.path.exists(subtitle):
39
  print("Transcribe or subtitle file doesn't exist")