Saturday, November 21, 2020
Create subtitle for your YouTube video on MacOS
If your language is supported by automatic captioning by YouTube, you are OK.
But if not, then you can create your own.
1) Basically, follow this "Creating translated subtitles with AI" article
Follow the steps in this article:
https://cloud.google.com/community/tutorials/speech2srt
However, some parts of the code needs to be updated to be compatible with current Speech API:
1-1) enums is deprecated
#encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16
encoding = speech_v1.RecognitionConfig.AudioEncoding.LINEAR16 #https://github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types
1-2) long_running_recognize
#operation = client.long_running_recognize(config, audio)
operation = client.long_running_recognize(request={"config":config, "audio":audio}) #https://stackoverflow.com/questions/64287266/google-speech-to-text-jupyterlab-notebook-script-run-locally-using-google-cloud
1-3) nanos is deprecated
#start_ms = int(w.start_time.nanos / 1000000)
start_ms = int(w.start_time.microseconds / 1000000) #https://github.com/googleapis/python-speech/issues/71
#end_ms = int(w.end_time.nanos / 1000000)
end_ms = int(w.end_time.microseconds / 1000000) #https://github.com/googleapis/python-speech/issues/71
2) Install ffmpeg for converting movie to audio file
3) Then you can execute the creation of SRT file to be uploaded to YouTube:
3-1) Download your video from YouTube Studio
3-2) Convert video to audio
Uncompressed WAV is best for speech to text
ffmpeg -i video.mp4 -ac 1 -ar 44100 audio.wav
3-3) Upload to Google bucket
../../../google-cloud-sdk/bin/gsutil cp audio.wav gs://$BUCKET_IN/
3-4) Do speech to text
python3 speech2srt.py --storage_uri gs://$BUCKET_IN/audio.wav --language_code id-ID --sample_rate_hertz 44100 --out_file audio
3-5) Upload audio.srt file to your YouTube video
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment