Skip to content

Add process_dataset.py #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: fast_inference_
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions GPT_SoVITS/process_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os


# Supporting third-party datasets with the format where each audio file corresponds to a text file.
# For example, voice01.wav -> voice01.txt.
def convert_dataset(input_folder, output_file, language='zh'):
audio_files = []
for f in os.listdir(input_folder):
if f.endswith('.wav'):
audio_files.append(f)

with open(output_file, 'w', encoding='utf-8') as output:

for audio_file in audio_files:
audio_path = os.path.join(input_folder, audio_file)
text_file = os.path.join(input_folder, audio_file.replace('.wav', '.txt'))

with open(text_file, 'r', encoding='utf-8') as text_content:
text = text_content.read().replace('\n', '')

speaker_name = os.path.splitext(audio_file)[0]

output_line = f'{audio_path}|{speaker_name}|{language}|{text}\n'
output.write(output_line)