Skip to content

Instantly share code, notes, and snippets.

@xiong-jie-y
Last active March 21, 2021 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiong-jie-y/277dd56e94bfe36d71e204cd7a34bf7a to your computer and use it in GitHub Desktop.
Save xiong-jie-y/277dd56e94bfe36d71e204cd7a34bf7a to your computer and use it in GitHub Desktop.
# pip install click
# pip install --upgrade "ibm-watson>=5.0.0"
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import click
@click.command()
@click.option("--filename")
@click.option("--input-text-file")
def main(filename, input_text_file):
authenticator = IAMAuthenticator(API_KEY)
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url(API_URL)
with open(filename, 'wb') as audio_file:
response = text_to_speech.synthesize(
open(input_text_file, 'r').read(), accept='audio/wav',
voice="en-US_MichaelVoice").get_result()
audio_file.write(response.content)
if __name__ == '__main__':
main()

英語音声/日本語字幕の発表動画を簡単に作る

作った動画はこれです。

https://www.youtube.com/watch?v=W3vWto6AU9Y&t=47s

まずはスライドを作る。

私はGoogle Slideで作りました。 ノートにスクリプトを書きました。

IBM Text To Speechで音声を作る

  1. IBM Cloudに登録
  2. Text To Speechサービスをアカウントに追加する。(https://www.ibm.com/cloud/watson-text-to-speech)
  3. 声を選ぶ。https://www.ibm.com/demos/live/tts-demo/self-service
  4. APIキーとURLを本Gist添付のスクリプトに入力 (API_KEYとAPI_URLを置き換えてください)
  5. 本Gist添付のスクリプトで音声を生成(コマンド例は次)1ページ1ページノートをtxtにして、次のコマンドで1ページ1ページ変換しました。
python create_voice.py --filename slides/3.wav --input-text-file slides/3.txt

音声を変えたい場合は、デモサイト(https://www.ibm.com/demos/live/tts-demo/self-service)を見ながら、19行目のvoice引数を変更してください。

スライドを録画する

スライドを表示させながら、タイミングよく作った音声を再生して、動画を作っていきます。

私はUbuntu環境なので、SimpleScreenRecorderを使いました。 PC内で再生されている音声も含めて録画できます。

Youtubeで字幕を作る

Youtubeに動画を非公開でアップします。 まずは、英語字幕をGoogle Slideのノートを結合して、字幕編集ページへアップロードします。 先程音声を作る際に作った.txtファイルを結合するのなら、次のコマンドで結合できます。

cat *.txt > total.txt

アップロードして、タイミング合わせボタンを押すと、いい感じに字幕を音声に合わせてくれるので、英語字幕はそれで完成です。 その後、日本語字幕を翻訳字幕機能で作ると、日本語の字幕付き英語音声の発表動画ができます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment