Saturday, 14 April 2018

Python code to read words in first column of excel sheet and convert all the words into individual audio files

import tts.sapi
import os
import openpyxl
import time

filename=str(raw_input('enter path to excel file: ')) # enter the complete path of excel file
wb = openpyxl.load_workbook(filename)
ws = wb.get_sheet_by_name('Sheet1') # gets Sheet1 in excel
rowcount=ws.max_row

def say(s):
    voice = tts.sapi.Sapi()
    voice.set_voice("Zira")#u can use the voice of David also
    #you set the rate to say slowly as shown below
    #voice.set_rate(-5)
    filename=str(ws.cell(row=i+1,column=1).value)+'.wav'
    voice.create_recording(filename, s)




if __name__== "__main__":

       for i in range(rowcount):              # loop through entire rows in excel

               mytext = str(ws.cell(row=i+1,column=1).value) # gets the first column data

               say(mytext)

1 comment:

  1. Inorder to run the above code
    You have to download the tts wrapper from the below link.
    https://github.com/DeepHorizons/tts

    Read the instructions in the below link to install the wrapper
    https://github.com/DeepHorizons/tts/blob/master/README.md

    ReplyDelete