Hello, this is my first post here and I have extremely little Python experience.
My goal is to use IBM Watson Text to Speech to read a .TXT file and output it to multiple .MP3 files.
I have been able to successfully do some of this using Jupyter Notebook and some code found in this video.
@3:15 you can see the code similar to what I'm using...
My question is…
Is it possible to split the audio into separate .MP3 files every time the .TXT file has an [enter] in it?
Example:
This is sentence number one. This is sentence number two.
[enter]
This is sentence number three. This is sentence number four.
[enter]
In the above scenario, sentence one and two would output as 001.mp3. Sentence three and four would output as 002.mp3. And so on.
Note that the separator doesn't have to be an [enter]. It can be a series of asterisks or whatever.
It looks like Jupyter Notebook uses "\n\n" as [enter]. Maybe that's where the split can happen.
I’m hoping someone could expand on the code I have…
Here is the code that reads the .TXT file...
Thank you!
My goal is to use IBM Watson Text to Speech to read a .TXT file and output it to multiple .MP3 files.
I have been able to successfully do some of this using Jupyter Notebook and some code found in this video.
@3:15 you can see the code similar to what I'm using...
My question is…
Is it possible to split the audio into separate .MP3 files every time the .TXT file has an [enter] in it?
Example:
This is sentence number one. This is sentence number two.
[enter]
This is sentence number three. This is sentence number four.
[enter]
In the above scenario, sentence one and two would output as 001.mp3. Sentence three and four would output as 002.mp3. And so on.
Note that the separator doesn't have to be an [enter]. It can be a series of asterisks or whatever.
It looks like Jupyter Notebook uses "\n\n" as [enter]. Maybe that's where the split can happen.
I’m hoping someone could expand on the code I have…
Here is the code that reads the .TXT file...
with open("test.txt") as text_file: text = text_file.read() text_file.close()Here is the code that outputs to audio MP3...
with open('./speech.mp3', 'wb') as audio_file: res = tts.synthesize(text, accept='audio/mp3', voice='en-US_MichaelV3Voice').get_result() audio_file.write(res.content)I can provide more code if necessary.
Thank you!