chompionsawelo commited on
Commit
77070f9
·
1 Parent(s): 1c1c8cf

minor fixes

Browse files
Files changed (3) hide show
  1. diarization.py +3 -3
  2. file_name.py +8 -3
  3. utils.py +16 -16
diarization.py CHANGED
@@ -1,6 +1,6 @@
1
  from pyannote.audio import Pipeline
2
  from pydub import AudioSegment
3
- import file_name
4
  import torch
5
  import json
6
  import gc
@@ -52,7 +52,7 @@ def audio_segmentation(input_file, speaker_groups_dict):
52
 
53
 
54
  def save_groups_json(sample_groups_list: list, speaker_groups_dict: dict):
55
- with open(file_name.sample_groups_json, "w", encoding="utf-8") as json_file_sample:
56
  json.dump(sample_groups_list, json_file_sample)
57
- with open(file_name.speaker_groups_json, "w", encoding="utf-8") as json_file_speaker:
58
  json.dump(speaker_groups_dict, json_file_speaker)
 
1
  from pyannote.audio import Pipeline
2
  from pydub import AudioSegment
3
+ from file_name import *
4
  import torch
5
  import json
6
  import gc
 
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)
file_name.py CHANGED
@@ -34,8 +34,13 @@ def get_video_subtitle_file():
34
  return f"{current_working_directory}/output_{get_title()}.mp4"
35
 
36
 
 
 
 
 
 
 
 
 
37
  start_time_for_adjustment = "00:00:00"
38
  end_time_for_adjustment = "01:00:00"
39
-
40
- sample_groups_json = "sample_groups.json"
41
- speaker_groups_json = "speaker_groups.json"
 
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"
 
 
 
utils.py CHANGED
@@ -4,14 +4,14 @@ import os
4
 
5
 
6
  def load_groups_json():
7
- sample_groups_list = []
8
- speaker_groups_dict = []
9
- if os.path.exists(sample_groups_json):
10
- with open(sample_groups_json, "r", encoding="utf-8") as json_file_sample:
11
- sample_groups_list: list = json.load(json_file_sample)
12
- if os.path.exists(speaker_groups_json):
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
 
@@ -35,12 +35,12 @@ def read_transcribe_subtitle_file(adjustment: bool):
35
  transcribe = get_transcribe_adjusted_file()
36
  subtitle = get_subtitle_adjusted_file()
37
 
38
- transcribe_txt_list = []
39
- subtitle_txt_list = []
40
- if os.path.exists(transcribe):
41
- with open(transcribe, "r", encoding="utf-8") as file:
42
- transcribe_txt_list = file.readlines()
43
- if os.path.exists(subtitle):
44
- with open(subtitle, "r", encoding="utf-8") as file:
45
- subtitle_txt_list = file.readlines()
46
  return transcribe_txt_list, subtitle_txt_list
 
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
 
 
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")
40
+ return [], []
41
+
42
+ with open(transcribe, "r", encoding="utf-8") as file:
43
+ transcribe_txt_list = file.readlines()
44
+ with open(subtitle, "r", encoding="utf-8") as file:
45
+ subtitle_txt_list = file.readlines()
46
  return transcribe_txt_list, subtitle_txt_list