Aug-29-2020, 03:23 AM
OK, I managed to cobble together some code after watching a few more tutorials...
Hope I did a good job... lol.
try: for FileNumber in range (1,1000): with open((str(FileNumber).zfill(3)) + ".txt") as text_file: text = text_file.read() FileName = ((str(FileNumber).zfill(3)) + ".txt") print (FileName) print (text) with open('./' + FileName + '.mp3', 'wb') as audio_file: res = tts.synthesize(text, accept='audio/mp3', voice='en-US_MichaelV3Voice').get_result() audio_file.write(res.content) except FileNotFoundError: print("No more files to convert!")The code will now...
- Begin with a maximum range of 999 files to look for
- Loop through each xxx.TXT file it finds (i.e. 001.TXT, 002.TXT, 003.TXT, etc.)
- Print the File Name
- Print the text inside the file
- Convert the text to speech and record an .MP3 file
- Stop when there are no more files left to convert (FileNotFoundError)
- Print "No more files to convert!" after it reaches the last file and causes an error
Hope I did a good job... lol.