Apr-24-2021, 10:25 PM
(This post was last modified: Apr-24-2021, 10:25 PM by Pedroski55.)
I have 10 text files and 10 mp3s
The text files have some lines with no time headers, but most lines look like this:
[11:29.53]Good morning, everyone.
I want all the time cues, like [11:29.53] gone, so I just have the text but no time cues.
I did it like this below, but I think it can be done more elegantly.
Any tips please?
The text files have some lines with no time headers, but most lines look like this:
[11:29.53]Good morning, everyone.
I want all the time cues, like [11:29.53] gone, so I just have the text but no time cues.
I did it like this below, but I think it can be done more elegantly.
Any tips please?
#! /usr/bin/python3
# tidy up text copied from Topway English CD
import os
path = '/home/pedro/Documents/topway/'
files = os.listdir(path)
for f in files:
print('Files are:', f)
file = input('What file are we looking for? Copy and paste 1 file here ... ')
textLoad = open(path + file)
textLoadData = textLoad.readlines()
textLoad.close()
newData = []
for line in textLoadData:
if line[0] == '[':
aLineCut = line[10:]
newData.append(aLineCut)
preparedText = ''.join(newData)
newFile = open(path + file + '_timeless', 'w')
newFile.write(preparedText)
newFile.close()
print('ALL DONE! File saved as ' + path + file + '_timeless')
