mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
Remove 0s durations from silence splitting
This commit is contained in:
1 parent
dad84ebdea
commit
849c281544
3 files changed
+76
-9
No files matched your search
@@ -186,9 +186,61 @@ class SilenceProcessingTest(unittest.TestCase):
|
||||
self.assertEqual(result[3].end, 8.0)
|
||||
self.assertEqual(result[3].is_hyphen, False)
|
||||
|
||||
# todo
|
||||
# | ** ** ** ***** | silence_parts_list
|
||||
# | *00**00**0 | multi silence is inside
|
||||
# |0 1 2 3 4 5 6 7 8 9 10 11 12| time
|
||||
def test_remove_no_duration_silence2(self):
|
||||
#
|
||||
# | * * * * * * | silence_parts_list
|
||||
# | 000 000 00000 | multi silence is inside
|
||||
# |0 1 2 3 4 5 6 7 8 | time
|
||||
|
||||
# Arrange
|
||||
|
||||
silence_parts_list = [(2.0, 2.1), (3.09, 3.1), (4.0, 4.09), (5.0, 5.09), (6.0, 6.09), (7.0, 7.09)]
|
||||
transcribed_data = [
|
||||
TranscribedData({
|
||||
"conf": 0.95,
|
||||
"word": "Remove split ",
|
||||
"end": 2.19,
|
||||
"start": 1.0
|
||||
}),
|
||||
TranscribedData({
|
||||
"conf": 0.95,
|
||||
"word": "Is split ",
|
||||
"end": 4.1,
|
||||
"start": 3.0
|
||||
}),
|
||||
TranscribedData({
|
||||
"conf": 0.95,
|
||||
"word": "Is split2 ",
|
||||
"end": 7.1,
|
||||
"start": 5.0
|
||||
}),
|
||||
]
|
||||
|
||||
# Act
|
||||
result = remove_silence2(silence_parts_list, transcribed_data)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(result[0].word, "Remove split ")
|
||||
self.assertEqual(result[0].start, 1.0)
|
||||
self.assertEqual(result[0].end, 2.0)
|
||||
self.assertEqual(result[0].is_hyphen, None)
|
||||
|
||||
self.assertEqual(result[1].word, "Is split ")
|
||||
self.assertEqual(result[1].start, 3.1)
|
||||
self.assertEqual(result[1].end, 4.0)
|
||||
self.assertEqual(result[1].is_hyphen, None)
|
||||
|
||||
self.assertEqual(len(result), 4) # "removed " is removed
|
||||
|
||||
self.assertEqual(result[2].word, "Is split2")
|
||||
self.assertEqual(result[2].start, 5.09)
|
||||
self.assertEqual(result[2].end, 6.0)
|
||||
self.assertEqual(result[2].is_hyphen, True)
|
||||
|
||||
self.assertEqual(result[3].word, "~ ")
|
||||
self.assertEqual(result[3].start, 6.09)
|
||||
self.assertEqual(result[3].end, 7.0)
|
||||
self.assertEqual(result[3].is_hyphen, False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -6,7 +6,6 @@ from pydub import AudioSegment, silence
|
||||
from modules.console_colors import ULTRASINGER_HEAD
|
||||
from modules.Speech_Recognition.TranscribedData import TranscribedData
|
||||
|
||||
|
||||
def remove_silence_from_transcription_data(audio_path: str, transcribed_data: list[TranscribedData]) -> list[
|
||||
TranscribedData]:
|
||||
"""Remove silence from given transcription data"""
|
||||
@@ -53,7 +52,7 @@ def remove_silence2(silence_parts_list: list[tuple[float, float]], transcribed_d
|
||||
# | ** ** | silence
|
||||
# | ********** | data
|
||||
# |0 1 2 3 4 5 6 | time
|
||||
if silence_start > data.start and silence_end < origin_end:
|
||||
if silence_start >= data.start and silence_end <= origin_end:
|
||||
next_index = silence_parts_list.index((silence_start, silence_end)) + 1
|
||||
if next_index < len(silence_parts_list) and silence_parts_list[next_index][0] < origin_end:
|
||||
split_end = silence_parts_list[next_index][0]
|
||||
@@ -73,13 +72,29 @@ def remove_silence2(silence_parts_list: list[tuple[float, float]], transcribed_d
|
||||
|
||||
if not was_split:
|
||||
data.end = silence_start
|
||||
|
||||
if data.end - data.start < 0.1:
|
||||
data.start = silence_end
|
||||
data.end = split_end
|
||||
continue
|
||||
|
||||
if split_data.end - split_data.start <= 0.1:
|
||||
continue
|
||||
|
||||
data.is_hyphen = True
|
||||
|
||||
# Remove last whitespace from the data.word
|
||||
if data.word[-1] == " ":
|
||||
data.word = data.word[:-1]
|
||||
|
||||
was_split = True
|
||||
new_transcribed_data.append(split_data)
|
||||
if split_data.end - split_data.start > 0.1:
|
||||
was_split = True
|
||||
new_transcribed_data.append(split_data)
|
||||
elif split_word == "~ " and data.is_hyphen:
|
||||
if new_transcribed_data[-1].word[-1] != " ":
|
||||
new_transcribed_data[-1].word += " "
|
||||
new_transcribed_data[-1].is_hyphen = False
|
||||
|
||||
continue
|
||||
|
||||
# | **** | silence
|
||||
|
||||
@@ -70,7 +70,7 @@ def create_ultrastar_txt_from_automation(
|
||||
ultrastar_bpm = real_bpm_to_ultrastar_bpm(bpm)
|
||||
multiplication = get_multiplier(ultrastar_bpm)
|
||||
ultrastar_bpm = ultrastar_bpm * get_multiplier(ultrastar_bpm)
|
||||
silence_split_duration = get_eighth_note_second(bpm)
|
||||
silence_split_duration = get_sixteenth_note_second(bpm)
|
||||
|
||||
with open(ultrastar_file_output, "w", encoding=FILE_ENCODING) as file:
|
||||
gap = transcribed_data[0].start
|
||||
|
||||
Reference in new issue
Block a user