-
Notifications
You must be signed in to change notification settings - Fork 1
Add logic to convert to srt #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| logger.info("Starting Transcription of Video File: %s" % video_file) | ||
| comment = transcribe_video_file(video_file) | ||
| output[video_file] = comment | ||
| convert_transcribe_to_srt(video_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to do a best-effort post-processing of comments within a try-catch block, so that if the post-processing of a single transcript fails we can still move on and complete the rest.
| else: | ||
| end = format_time(items[len(items)-1]['end_time']) | ||
|
|
||
| with open(transcript_file_name_from_video_file_name(video_file).replace('.json', '.srt'), 'w', encoding='utf-8') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd like to create one new srt file and one new txt file containing the topmost ranked transcript.
| logger.info("Conversion to srt started for video file: %s" % video_file) | ||
| with open(transcript_file_name_from_video_file_name(video_file), encoding='utf-8') as f: | ||
| raw = json.load(f) | ||
| items = raw['results']['items'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if results are null or empty and items are null or empty, log the same and move on.
| start = format_time(current) | ||
| if token['type'] == 'punctuation': | ||
| next_line = next_line[0:-1] + token['alternatives'][0]['content'] | ||
| end = format_time(items[counter - 1]['end_time']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the punctuation is at the beginning of the transcript, won't this throw an index-out-of-bounds exception ?
| next_line = token['alternatives'][0]['content'] + ' ' | ||
| current = float(token['start_time']) | ||
| else: | ||
| next_line += token['alternatives'][0]['content'] + ' ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like any token with end_time - start_time > 5.0 will be written to the srt file. However, I'm not seeing how a sequence of tokens with smaller individual time spans will be strung together in a single sentence ?
ramnanib2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work ! Thanks for making the changes. Some minor comments. I think the logic within can be simplified a little within the items loop.
Things left to do: