123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- from audio import combine_two_files
- from files import get_txt_files
- from models import SpeakerModel, Device, SampleRate
- from text import get_separated_text_from_file
- tts = SpeakerModel()
- # Can provide language, device, sample rate and model id
- # Default 'ru' 'cpu' 48000 v3_1_ru
- tts.specify_model()
- info = tts.get_model_info()
- files = get_txt_files()
- if not files:
- exit("WARNING! There is no txt files in folder 'files'. Please create \
- one and run again")
- output_audio_filename = input("Type output file name: ") or "audio"
- while True:
- speaker = input(f"Select voice. Type one of: {'/'.join(info.speakers)}: ") \
- or info.speakers[0]
- if speaker in info.speakers:
- break
- else:
- print('WARNING! Incorrect voice name. Try again')
- print(f"Selected voice - {speaker}")
- for i, file in enumerate(files):
- try:
- paragraphs = get_separated_text_from_file(file)
- except Exception as e:
- print("Aborting program cause file can't be opened")
- exit()
- if len(files) == 1 and output_audio_filename:
- audio_filename = f"files/{output_audio_filename}-{speaker}.wav"
- else:
- filename = ''.join(file.split('/')[-1].split('.')[:-1])
- audio_filename = f"files/{''.join(file.split('/')[-1].split('.')[:-1])}-{speaker}-{output_audio_filename}.wav"
- for j, p in enumerate(paragraphs):
- # push("Processing...", f"File {i+1}/{len(files)} paragraph {j+1}/{len(paragraphs)}")
- print("Processing...", f"File {i+1}/{len(files)} paragraph {j+1}/{len(paragraphs)}")
- try:
- tts.text2speech(p, "files/temp.wav", speaker=speaker)
- except Exception as e:
- print(e)
- combine_two_files([audio_filename, "files/temp.wav"], audio_filename)
- print(f"File {audio_filename} was finished")
- print("Al files were finished")
|