I. Why convert txt to subtitle
1.1 Convenient to editing software editing
Sometimes you get a piece of text and want to drag and drop it directly into the editing software, at this time, generate a srt file from the text, you can generate the corresponding clip in the editing software, you just need to drag and drop it to fit the screen.
1.2 Automatic generation of subtitles for videos
After obtaining a piece of text through a crawler, the keywords in the text can be extracted, a suitable image can be found, and audio can be generated based on the text. The duration of the audio can be calculated. Generate subtitles according to the duration.
This completes the process of generating a video from a text.
II. Operational process
I'll use a Python script to teach you how to quickly generate a subtitle file. It's easy for you to generate a subtitle file quickly when you are making subtitles. The file I'm generating here is an srt file.
First prepare a text with aTXT
The format of the text is shown below:
For each sentence you are going to say, write it up and then change the line. Remember to leave the first line blank.
If you're a paragraph of text, you can use Python's snownlp library to branch branches.
The file is shown in the screenshot below:
Finally, through the script
Generate afile
You can just drag and drop it into your editing program.
Third, the realization of the code is as follows
The code is as follows:
f2= open(r"D:\Automation\",'w',encoding='utf-8-sig') # Returns a file object line=()# Call the file's readline() method no=1 start_time = ('00:00:00','%H:%M:%S') end_time = ('00:00:00','%H:%M:%S') while line: line= () start_time=start_time+(seconds=4) end_time=start_time+ (seconds=8) str_start_time = (start_time,'%H:%M:%S') str_end_time =(end_time,'%H:%M:%S') (str(no)+'\n') (str_start_time+",433"+"-->"+str_end_time+",433"+'\n') (line+'\n') no=no+1 () ()
to this article on the Python realization of a paragraph txt generate subtitles srt file is introduced to this article, more related Python generate subtitles srt file content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!