Skip to content

Instantly share code, notes, and snippets.

@hexvolt
Created January 29, 2017 20:31
Show Gist options
  • Save hexvolt/fccec9a0f62616b9ad608dbb4f04cad0 to your computer and use it in GitHub Desktop.
Save hexvolt/fccec9a0f62616b9ad608dbb4f04cad0 to your computer and use it in GitHub Desktop.
Small script to get the .mp3 pronunciations of the phrases specified in the .csv file
import csv
from gtts import gTTS
from tempfile import TemporaryFile
FILE_NAME = '{{input_file_name}}.csv'
def main():
with open(FILE_NAME, 'r') as input_file:
reader = csv.reader(input_file)
for row in reader:
phrase = row[0].strip()
mp3_file_name = '_'.join(phrase.split()) + '.mp3'
print(mp3_file_name)
tts = gTTS(text=phrase, lang='en')
with open(mp3_file_name, 'w') as output_file:
tts.write_to_fp(output_file)
if __name__ == '__main__':
main()
argparse==1.2.1
gTTS==1.1.7
gTTS-token==1.1.1
requests==2.12.4
wsgiref==0.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment