updating utils

This commit is contained in:
YongeBai 2023-10-04 16:04:08 +08:00
parent 02e3a46700
commit a1d0ea3232

View File

@ -38,7 +38,7 @@ def process_textfile(file_path: str) -> list[str]:
text = clean_text(text) text = clean_text(text)
return text return text
def tts(paper_name: str): def tts(file_path: str):
# load tts model # load tts model
# ADD PATH # ADD PATH
tts = TextToSpeech( tts = TextToSpeech(
@ -50,7 +50,7 @@ def tts(paper_name: str):
) )
# process text file # process text file
texts = process_textfile(f"./llm/scripts/{paper_name}.txt") texts = process_textfile(file_path)
# generate audio for each chunk of text # generate audio for each chunk of text
all_audio_chunks = [] all_audio_chunks = []
@ -65,6 +65,9 @@ def tts(paper_name: str):
all_audio_chunks.append(gen) all_audio_chunks.append(gen)
book_name_ext = os.path.basename(file_path)
paper_name = os.path.splitext(book_name_ext)[0]
# concatenate all audio chunks # concatenate all audio chunks
full_audio = torch.cat(all_audio_chunks, dim=-1) full_audio = torch.cat(all_audio_chunks, dim=-1)
torchaudio.save(f"./audio/raw/{paper_name}.wav", full_audio, 24000) torchaudio.save(f"./audio/raw/{paper_name}.wav", full_audio, 24000)