ChatGPTに聞いて、Whisperを使った動画の音声を英語から日本語に翻訳する方法を実践してみました。半日仕事でできてしまいます。できたコンテンツの確認にはちょっと別の方法も考えないと厳しいですね。
目次
まとめ
- FFmpegを導入して動画から音声を抽出できる
- Whisperで音声を文字起こし(Pythonで処理)
- 字幕ファイル(SRT)を作成(オプション)ここではやってません。
この方法を使えば、YouTube動画の字幕作成や会議録画の文字起こしが簡単にできます。
1.動画から音声ファイル抽出
Whisperは音声ファイルしか処理できないので動画ファイルから音声を取り出す必要があります。FFmpegをインストールして、これを使って抽出します。FFmpegに処理させるYoutube動画のダウンロードはyt-dlp.exeにて行います。
yt-dlp URL(https://www.youtube.com/watch?v=OOOOOなど)
ffmpeg -i video.mp4 -q:a 0 -map a audio.mp3
このコマンドでvideo.pm4ファイルからaudio.mp3で音声を抽出できます。
モノラルで抽出する場合には下記のオプションになります。(16kHz, モノラルのWAV形式で保存)
ffmpeg -i video.mp4 -acodec pcm_s16le -ar 16000 -ac 1 audio.wav
2.音声からテキストファイルに変換
PythonでWhisperを使用します。注意点ですが、現時点(2025/3/1)ではWhisperはpython3.11.9でしか動作しません。エラーになります。そこで、pythonはダウングレードする必要があります。最新は3.13なのでこれをダウングレードします。必要に応じて仮想環境でWhisperをpythonに追加します。
pip install openai-whisper
依存関係を解決してくれるので自動で関連モジュールも導入してくれますので時間はかかります。完了するとプログラムは4行だけです。
app.py
import whisper
# Whisperのモデルをロード(例: “small”)
model = whisper.load_model(“small”)
# 抽出した音声をテキストに変換
result = model.transcribe(“audio.mp3”)
# 文字起こし結果を表示
print(result[“text”])
small のほかに、tiny, base, medium, large などのモデルを選べます(大きいほど精度が高いが処理が重い)同じフォルダの下にaudio.mp3を置いておきます。テキストはターミナル画面に表示されます。
ディクテーションされた英文
And now I’m talking with my friends in Poland, and they are warned that you align yourself too much with Putin. What’s your message for them? Well, if I didn’t align myself with both of them, you’d never have a deal. He wanted me to say really terrible things about Putin and then say, hi, Vladimir, how are we doing on the deal? But it doesn’t work that way. I’m not aligned with Putin. I’m not aligned with anybody. I’m aligned with the United States of America. And for the good of the world. I’m aligned with the world. And I want to get this thing over with. You see the hatred he’s got for Putin? It’s very tough for me to make a deal with that kind of hate. He’s got tremendous hatred. And I understand that, but I can tell you the other side isn’t exactly in love with him either. So it’s not a question of alignment. I’m aligned with the world. I want to get the things that I’m aligned with Europe. I want to see if we can get this thing done. You want me to be tough? I could be tougher than any human being you’ve ever seen. I’d be so tough, but you’re never going to get a deal that way. So that’s the way it goes. One more question. I would respond to this. So look, for four years in the United States of America, we had a president who stood up at press conferences and talked tough about Vladimir Putin, and then Putin invaded Ukraine and destroyed a significant chunk of the country. The path to peace and the path to prosperity is maybe engaging in diplomacy. We tried the pathway of Joe Biden of thumping our chest and pretending that the president of the United States’ words mattered more than the president of the United States’ actions. What makes America a good country is America engaging in diplomacy. That’s what President Trump is doing. Can I ask you? Sure. John? Yeah. He occupied our parts, big parts of Ukraine, parts of East and Crimea. So he occupied it on 2014. So during a lot of years, I’m not thinking about just Biden, but those time was Obama, then President Obama, then President Trump, then President Biden, now President Trump, and God bless, now President Trump will stop him. But during 2014, nobody stopped him. He just occupied and took. He killed people. You know what the contact line? 2015. 2014. 2014 is 2014. Well, 2014. Yeah, yeah. So he killed… I was not here. Yeah, but… That’s exactly right. Yes, but during 2014 till 2022, what the situation is the same, that people have been dying on the contact line. Nobody stopped him. You know that we had conversations with him. A lot of conversations, my bilateral conversation. And we signed with him, me, like a new president in 2019. I signed with him the deal. I signed with him Macron and Merkel. We signed ceasefire. Ceasefire. All of them told me that he will never go. We signed him with gas contraband. Gas contraband. Yes, but after that, he broke in the ceasefire. He killed our people and he didn’t exchange prisoners. We signed the exchange of prisoners, but he didn’t do it. What kind of diplomacy, GD, you are speaking about? What do you mean? I’m talking about the kind of diplomacy that’s going to end the destruction of your country. Yes, but if you don’t want to go… Mr. President, with respect, I think it’s disrespectful for you to come into the Oval Office and try to litigate this in front of the American media. Right now, you guys are going around and forcing conscripts to the front lines because you have manpower problems. You should be thanking the President for trying to bring it into this conflict. Have you ever looked into Ukraine? Did you say what problems we have? I have been to… And come what? I’ve actually watched and seen the stories and I know what happens is you bring people, you bring them on a propaganda tour, Mr. President. Do you disagree that you’ve had problems bringing people into your military? Do you have problems? And do you think that it’s respectful to come to the Oval Office of the United States of America and attack the administration that is trying to prevent the destruction of your country? A lot of questions. Let’s start from the beginning. Sure. First of all, during the war, everybody has problems. Even you, but you have nice ocean and don’t feel now, but you will feel it in the future. God bless you. You don’t know that. God bless you. God bless you. God bless you. God bless you. God bless you. You will not have a war. Don’t tell us what we’re going to feel. We’re trying to solve a problem. Don’t tell us what we’re going to feel. I’m not telling you. I’m not telling you. I’m not telling you. You’re in no position to dictate what we’re going to feel. You will feel influence. We’re going to feel very good and very strong. You will feel influence. You’re right now not in a very good position. You’ve allowed yourself to be in a very bad position at his embassy right about now. From the very beginning of the war. You’re not in a good position. I was about to say that. You don’t have the cards right now. With us, you start having cards. You’re not playing cards. But right now, you’re not playing cards. I’m going to steal your misprint. You’re playing cards. I’m going to steal it. You’re gambling with the lives of millions of people. You’re gambling with World War III. You’re gambling with World War III. And what you’re doing is very disrespectful to the country, this country, that’s back to you far more than a lot of people said they should have. Have you said thank you once? There’s a lot of times. No, in this entire meeting that you said thank you, you went to Pennsylvania and campaign for the opposition in October, all for some words of appreciation for the United States of America and the president who’s trying to save your country. Please, you think that if you will speak very loudly about the war, you can’t speak loudly. He’s not speaking loudly. Your country is in big trouble. Can I answer? Wait a minute. No, no, we’ve done a lot of talking. Your country is in big trouble. I know. You’re not winning. You’re not winning this. I… You have a damn good chance of coming out okay because of us. We are staying in our country, staying strong from the very beginning of the war. We’ve been alone and we are thankful. I said thanks in this cabinet. You haven’t been alone. We gave you through the stupid president $350 billion. You voted for your president. We gave you military equipment and you men are brave but they had to use our military equipment. If you didn’t have our military equipment, if you didn’t have our military equipment, this war would have been over in two weeks. In three days, I heard it from Putin. In three days, this is something you do in two weeks. Of course, yes. It’s going to be a very hard thing to do business like this. I tell you. Just say thank you. I said it at all times. Except with their… Except with the American people. Except that there are disagreements and let’s go litigate those disagreements rather than trying to fight it out in the American media when you’re wrong. We know that you’re wrong. But you see, I think it’s good for the American people to see what’s going on. I understand. I understand. I understand. I think it’s very important. That’s why I kept this going so long. You have to be thankful. You don’t have the cards. I’m thankful. You’re buried there. You’re people that died. I can tell you that you’re… You’re running low on soldiers. Don’t listen. Don’t play this game. You’re running slow on soldiers. It would be a damn good thing if you… You’re disappeared. Then you tell us, I don’t want a ceasefire. I don’t want a ceasefire. I want to go and I want this. Look, if you could get a ceasefire right now, I tell you, you take it so the bullets stop flying and your men stop getting killed. Of course, we want to stop the war. But I said… But I said to you… I want a ceasefire. We’re guaranteed. Because you’ll get a ceasefire faster than any agreement. How are people about a ceasefire? What do they think? It doesn’t matter for you what… That wasn’t with me. It wasn’t with you. That was with a guy named Biden who was not a smart person. That was with Obama. It was your brother. Excuse me. That was with Obama who gave you sheets and I gave you javelins. I gave you the javelins to take out all those tanks. Obama gave you sheets. In fact, the statement is Obama gave sheets and Trump gave javelins. You got to be more thankful because let me tell you, you don’t have the cards. With us, you have the cards. But without us, you don’t have any cards. One more question to my leader, Vice President. I’m sorry. It’s going to be a tough deal to make because the attitudes have to change. What if Russia breaks the ceasefire? What if Russia breaks these talks? What do you do then? I understand that it’s a heated conversation right now. What are you saying? She’s asking what if Russia breaks the ceasefire? What if anything? What if a bomb drops on your head right now? Okay? What if they broke it? I don’t know. They broke it with Biden because Biden didn’t respect him. They didn’t respect Obama. They respect me. Let me tell you, Putin went through a hell of a lot with me. He went through a phony witch hunt where they used him and Russia, Russia, Russia, Russia. You ever hear of that deal? There was a phony Hunter Biden, Joe Biden scam. Hillary Clinton, shifty Adam Schiff. It was a Democrat scam. And he had to go through that. And he did go through it. We didn’t end up in a war. He went through it. He was accused of all that stuff. He had nothing to do with it. It came out of Hunter Biden’s bathroom. It came out of Hunter Biden’s bedroom. It was disgusting. And then they said, oh, oh, the laptop from hell was made by Russia, the 51 agents. The whole thing was a scam. And he had to put up with that. He was being accused of all that stuff. All I can say is this, he might have broken deals with Obama and Bush, and he might have broken them with Biden. He did. Maybe. Maybe he did. I don’t know what happened. But he didn’t break them with me. He wants to make a deal. I don’t know if he can make a deal. The problem is, I’ve empowered you to be a tough guy. And I don’t think you’d be a tough guy without the United States. And your people are very brave. But you’re either going to make a deal or we’re out. And if we’re out, you’ll fight it out. I don’t think it’s going to be pretty, but you’ll fight it out. But you don’t have the cards. But once we sign that deal, you’re in a much better position. But you’re not acting at all thankful. And that’s not a nice thing. I’ll be honest. I think we’ve seen enough. What do you think? This is going to be great television. I will say that. We’ll see what we can do about it. We’ll see. I need the back to the side. We’ll see. I don’t think that’s possible. Wait, wait, wait. Hey, my boss. Guys, come on.
ChatGPTの翻訳
質問者:
「今、私はポーランドの友人たちと話していますが、彼らはあなたがプーチンとあまりにも歩調を合わせていると警戒しています。彼らに向けたメッセージはありますか?」
回答者:
「もし私が両者と歩調を合わせていなかったら、合意など成立しなかったでしょう。彼は私にプーチンのことをひどく批判させた上で、『やあ、ウラジーミル、取引の進捗はどうだい?』と言わせたかったのでしょう? でも、それはうまくいきません。私はプーチンと歩調を合わせているわけではありません。誰とも歩調を合わせていません。私はアメリカ合衆国のために行動しています。そして世界のために。私は世界と歩調を合わせています。この問題を終わらせたいのです。
あなたは、彼(別の指導者)がプーチンに対してどれだけ強い憎しみを抱いているか見ていますか? そんな憎しみを持つ相手とは交渉が非常に難しいのです。彼の憎しみは尋常ではありません。でも、相手側(ロシア)も彼を愛しているわけではないのです。これは誰に味方するかという問題ではありません。私は世界と歩調を合わせています。ヨーロッパとも協力し、この問題を解決したいのです。
あなたは私に強硬な態度を取ってほしいのですね?私は誰よりも強硬に対応することもできます。でも、それでは取引は成立しません。そういうものなのです。」
別の質問者:
「では、アメリカには4年間、プーチンに対して強硬な発言を繰り返してきた大統領がいましたが、その結果、プーチンはウクライナへ侵攻し、国の大部分を破壊しました。平和と繁栄への道は、むしろ外交を通じた交渉ではないでしょうか? ジョー・バイデンが胸を張って強硬姿勢を示しても、大統領の言葉が大統領の行動よりも重要だと信じ込むだけでは意味がありません。アメリカを良い国たらしめているのは、外交による関与です。それがトランプ大統領のやっていることです。」
ウクライナ側の代表:
「しかし、2014年にロシアはウクライナ東部やクリミアの広範囲を占領しました。その間、オバマ大統領、トランプ大統領、バイデン大統領がいましたが、誰もロシアを止めることができませんでした。2014年から2022年まで、戦闘が続き、人々が死んでいました。私たちはロシアと多くの交渉を行い、2019年に私が大統領になった際には、マクロンやメルケルと共に停戦合意にも署名しました。彼らはロシアがもう進軍しないと言いました。しかし、ロシアは停戦を破り、私たちの人々を殺し、捕虜交換にも応じませんでした。あなたが言う『外交』とは、一体何を指しているのですか?」
回答者:
「私は、あなたの国の破壊を終わらせるための外交について話しているのです。」
ウクライナ代表:
「しかし、大統領、アメリカのメディアの前でこのような話をするのは失礼ではありませんか? 今、あなたの国は徴兵の問題を抱えており、前線に兵士を送り込むのが困難になっています。大統領がこの紛争を終わらせようとしていることに感謝すべきではありませんか?」
議論がヒートアップする場面
回答者:
「アメリカはあなた方に多くの支援をしました。感謝の言葉を述べたことがありますか? 10月にはペンシルベニア州でアメリカ政府を批判しましたね。それなのに、アメリカに感謝の言葉は一度もない。」
ウクライナ代表:
「我々は戦争の初日から自国に留まり、戦い続けています。そして、感謝の言葉も述べています。」
回答者:
「アメリカは3500億ドルの支援をしました。武器も提供しました。オバマ政権は毛布しか送らなかったが、私はジャベリン(対戦車ミサイル)を送った。アメリカの支援がなければ、この戦争は2週間で終わっていたでしょう。プーチンは3日で終わらせるつもりだったと言っていました。」
質問者:
「では、ロシアが停戦を破ったらどうするのですか?」
回答者:
「ロシアが停戦を破ったら? それは分かりません。バイデンが大統領だった時、ロシアは停戦を守りませんでした。オバマの時も同じです。でも私の時は違いました。私はロシアと取引をしました。あなた方には強い立場で交渉する力があるが、それはアメリカの支援があってこそです。我々が去れば、ウクライナは戦い続けるしかありません。それは決して良い状況ではないでしょう。だからこそ、合意を結ぶべきなのです。」
最後のやりとり:
回答者:
「あなた方は、もっと感謝の気持ちを示すべきです。感謝の気持ちがないのは良くありません。正直に言いますが、それは良くないことです。」
「もう十分でしょう。どう思いますか? これは良いテレビ番組になるでしょうね。」
「では、これで終わりにしましょう。」