見出し画像

【会話可能なチャットボットの作り方】英語解説を日本語で読む【2023年6月25日|@The AI Advantage】

音声でコミュニケーションが可能なチャットボットを作成することについて語っています。初心者でも簡単にボットを作成でき、ステップバイステップのガイダンスを提供します。ElevenLabs APIを紹介し、ボットに現実的で人間らしい声を与えることができるようにします。必要なツールと依存関係の設定方法についての手順も提供しています。音声対話の例を挙げることでチャットボットの機能を実証します。無料の音声応答にGoogle Text-to-Speechを統合する方法と、より現実的な声にElevenLabsを使用する方法を説明します。
公開日:2023年6月25日
※動画を再生してから読むのがオススメです。


I'm very excited about this one because today we'll be making a chat bot on your phone that you can talk into and it actually talks back.

このたびは非常にワクワクしています。なぜなら、今日はあなたの携帯電話でチャットボットを作成し、話しかけると実際に返事をすることができるからです。

That is Sensei Igor for you.

それがイゴール先生です。

Apologies, Sensei Igor.

申し訳ありません、イゴール先生。

I will make sure to address you correctly in the future.

将来的には正しくあなたにお呼びするようにします。

And the best part is, this is actually very easy to build, even for beginners.

そして最高の部分は、これは実際に初心者でも非常に簡単に作成できるということです。

I'll be holding your hand for the entire process, step by step, as we first build a version that is completely free.

このプロセス全体で手を取り合いながら、ステップバイステップで最初に完全に無料のバージョンを作成します。

And then the second version, we'll use the ElevenLabs API, giving you a chatbot voice that sounds like a real human.

そして、2番目のバージョンでは、ElevenLabsのAPIを使用して、本物の人間のような声を持つチャットボットの声を提供します。

Greetings, my beloved Master.

こんにちは、私の愛しいマスター。

As requested, I will gladly provide you with an essay about penguins.

ご要望にお応えして、ペンギンについてのエッセイを喜んで提供いたします。

But look, everything covered in this video is extremely beginner-friendly, which means it's not all it could be, right?

ただし、このビデオでカバーされているすべては、非常に初心者向けになっていますので、これがすべてではないことに注意してくださいね。

If you happen to need a custom chatbot or you want to make your company more efficient by implementing AI, well, here for the first time, I'm announcing the AI Advantage agency.

もしカスタムのチャットボットが必要な場合や、AIを導入して会社を効率化したい場合は、今回初めてAI Advantageエージェンシーを発表します。

Me and my team are already helping businesses implement AI, build chatbots, and so much more.

私と私のチームは既にビジネスのAI導入やチャットボットの構築などを手助けしています。

So check it out under the following link.

以下のリンクでチェックしてみてください。

And now, back to the video.

そして、ビデオに戻ります。

Again, all of this has been prepared to be extremely beginner-friendly.

もう一度言いますが、これは非常に初心者向けに準備されています。

But what this is, is part 3 of my mini-series that I released on my YouTube for free.

ただし、これは私がYouTubeで無料で公開したミニシリーズのパート3です。

So if you're completely new to this, you have to watch those two videos because we'll be building upon that knowledge and the steps we did in those two tutorials.

ですので、これが初めての方は、前回の2つのビデオを見る必要があります。なぜなら、この知識と前の2つのチュートリアルで行った手順に基づいて進めていくからです。

They too are extremely beginner-friendly and they cover most of what we need here.

それらも非常に初心者向けであり、ここで必要なほとんどの内容をカバーしています。

Because first of all, we need an IDE which is set up in the first episode.

まず第一に、最初のエピソードでセットアップされたIDEが必要です。

Secondly, you need your OpenAI API key which I showed you how to get in the first episode.

第二に、OpenAIのAPIキーが必要です。最初のエピソードで取得方法を紹介しました。

That couldn't be any simpler.

それは非常に簡単です。

And thirdly, we'll need the telegram bots to which I introduced to in the second episode.

そして第三に、第二エピソードで紹介したTelegramのボットが必要です。

Because again, this easy to build chatbot will be based within telegram.

なぜなら、この簡単に作成するチャットボットはTelegram内で動作するからです。

You'll be speaking to it, it will be speaking back to you.

あなたはそれと話をすることができ、それはあなたに返事をします。

I apologize if using the term master and all inside of an app that all of us can get on our phones.

私たち全員が携帯電話で手に入れることのできるアプリ内で「マスター」という用語を使うことで申し訳ありません。

The only thing that is new here is the code for today's video.

ここで新しいのは、今日のビデオのコードだけです。

As per usual, you can download that from the description below or copy it up from my GitHub.

いつものように、それは以下の説明からダウンロードするか、私のGitHubからコピーすることができます。

If you're more advanced, and these are the four files on there.

もしあなたがより高度なユーザーなら、そこには4つのファイルがあります。

So the first one is the old code from the second video that we'll be building up on.

最初のファイルは、私たちが基礎となる第2のビデオの古いコードで、それを基にして構築していきます。

Secondly, we'll be building a free version of this chatbot with the Google Text-to-Speech integration, which is completely free and gives the chatbot the ability to talk back to you.

第二に、Google Text-to-Speechの統合を使用して、このチャットボットの無料バージョンを作成します。それは完全に無料で、チャットボットがあなたに返事をする能力を持ちます。

And thirdly, we'll be using ElevenLabs API because their voices actually sound like real humans.

そして第三に、ElevenLabsのAPIを使用して、彼らの声が実際の人間のように聞こえるチャットボットを作成します。

There is a free trial, but if you want to keep using it, that will cost some money.

無料トライアルがありますが、それを継続的に使用する場合は一定の費用がかかります。

So first things first, as in previous tutorials, I will just grab this folder and drag it onto Visual Studio code.

まず最初に、前のチュートリアルと同様に、このフォルダをVisual Studio codeにドラッグアンドドロップするだけです。

All right, and here are the files we need.

はい、そして必要なファイルがここにあります。

But as the very first step, we want to install all these requirements because that will make sure we have all the packages we need moving forward.

ただし、非常に最初のステップとして、前に進むためにこれらの要件をすべてインストールしたいと思います。

And we don't need to install them one by one while moving for this.

それによって、1つずつインストールする必要はありません。

A very brief overview here would be that this is the Google Text-to-Speech, which allows us to transform text into speech for free.

ここで非常に簡単な概要を説明しますが、これはGoogle Text-to-Speechで、テキストを音声に変換することができます(無料で利用できます)。

Movie Pi allows us to work with audio files inside of our little scripts here so that the chatbot can understand the voice notes we record.

Movie Piは、ここでオーディオファイルを扱うためのライブラリであり、録音した音声メモをチャットボットが理解できるようにします。

Numpy is a library that is required for the ElevenLabs library to work.

NumpyはElevenLabsライブラリの動作に必要なライブラリです。

And the ElevenLabs library is the one that will give us those realistic human-like voices that we're looking for here.

ElevenLabsライブラリは、私たちがここで求めている現実的な人間のような声を提供します。

And then, these two are kind of obvious.

そして、これら2つは明らかですね。

OpenAI allows us to interact with Jet GPT, and Python Telegram Bot allows us to call the Telegram bot from within here.

OpenAIはJet GPTとの対話を可能にし、Python Telegram BotはここからTelegramボットを呼び出すことができます。

That works easily on any phone.

それはどの携帯電話でも簡単に機能します。

Alright, enough talking, let's start doing.

わかりました、話すのをやめてやりましょう。

Go to terminal, new terminal, and inside of here, you need to run one command to install all of this at once.

ターミナルに移動し、新しいターミナルを開きます。そして、ここで一度にすべてをインストールするためのコマンドを実行する必要があります。

On Mac, that is pip free install -r requirements.txt.

Macの場合は、「pip free install -r requirements.txt」というコマンドです。

As that is the file, and by hitting enter, I will install all of these packages onto my computer.

それがファイル名です。エンターキーを押すことで、これらのパッケージをすべてコンピュータにインストールします。

Looking good.

うまくいっていますね。

If you're Windows, you can run the same command just without the free, so it's pip install -r requirements.txt.

もしWindowsをお使いの場合は、同じコマンドを「pip install -r requirements.txt」と入力します(freeを省いた形で)。

And with that, we're all set up, which makes us ready to dive into the code which will make the magic happen.

これで準備完了です。

And as you can see, I did include the old code that we're building on top of here for learning purposes, as I find this extremely useful.

ご覧の通り、学習目的で私はここに私たちが基盤として構築している古いコードも含めましたが、これは非常に有用だと思います。

Then, you can switch back and forth and see what's changed with the new chat bot.

その後、切り替えて新しいチャットボットで何が変わったかを見ることができます。

But again, even this old code was super simple.

しかし、この古いコード自体も非常にシンプルです。

You're bringing all the packages that make all this happen, then you link your accounts with the API keys.

この部分では、すべてを実現するためのパッケージを取り込み、アカウントをAPIキーでリンクさせます。

This part includes ChatGPT, and here we integrated into Telegram.

この部分にはChatGPTが含まれており、Telegramに統合されています。

This function makes the voice input into the Telegram bot happen, and last but not least, this bottom part launches the Telegram bot and keeps it running while we keep the script running.

この関数は、音声入力をTelegramボットで実現し、最後にこの下部の部分でTelegramボットを起動し、スクリプトを実行している間は常に稼働させます。

And by opening up the 01 GTTS, which stands for Google Text-to-Speech, we are ready to take this a step further and allow the bot to talk back to us.

GTTS(Googleテキスト読み上げ)という01を開くことで、さらに一歩進んでボットが話し返すことができるようになります。

And as you might have already noticed, there is no new API key, and that is because this service is completely free.

そして、既にお気づきかもしれませんが、新しいAPIキーはありません。それはこのサービスが完全に無料だからです。

You can use it as often as you want.

いつでも自由に使用できます。

It's not very high quality, but it will speak to you, and it costs no money.

それはあまり高品質ではありませんが、あなたに話しかけることができ、お金はかかりません。

So it's perfect to experiment with.

だから、実験には最適です。

Of so, first things first, I'll copy-paste my OpenAI API key into here.

それではまずは、OpenAIのAPIキーをここにコピー&ペーストします。

Now we're linked to ChatGPT.

こうしてChatGPTにリンクされました。

Secondly, we'll paste our Telegram API token that we got from the BotFather, just like I showed you in the last video.

次に、最後のビデオでお見せしたように、BotFatherから取得したTelegramのAPIトークンをここに貼り付けます。

And guess what?

そして、分かりますか?

That is kind of it.

それでだいたい終わりです。

We're ready to go.

準備完了です。

And this would already work, as I provided you with the code here.

これはすでに機能します。ここにコードを提供しましたので。

I'll just briefly point out that this is where most of the magic happens, where it takes the text, responds, saves it as an MP3.

簡単に説明すると、テキストを取り、応答してMP3として保存するのがほとんどの魔法が起こる場所です。

And then, sends it back to the telegram bot, taking the ChatGPT answer and presenting it to you through the voice that Google Text-to-Speech creates.

そして、それをテキスト読み上げであるGoogle Text-to-Speechの声に変換し、Telegramボットに送り返すのがこの下部の部分です。

Here and then down here, it's the same thing.

そして、こことここでも同じことが行われています。

All we need to do now is press play, like so, and the script is running.

今やプレイボタンを押すだけで、スクリプトが実行されます。

And all of a sudden, our bot inside of telegram should be able to respond with voice messages.

すると、Telegram内のボットが突然音声メッセージで応答するはずです。

Let's test it out.

試してみましょう。

So what we're going to do here is just press start.

では、ここで「スタート」と押すだけです。

Once we start this brand new bot, we can record a voice message into it.

この新しいボットを開始すると、それに音声メッセージを録音できます。

Write me an essay about penguins, as per usual.

いつも通り、「ペンギンについてのエッセイを書いてください」と入力してみましょう。

And there we go.

そして、そこに行きます。

It shows us, I've received a voice message.

それは私たちに、音声メッセージを受け取ったことを示しています。

Please wait.

お待ちください。

And it also shows my input, Write me an essay about penguins.

そして、私の入力も表示されています。「ペンギンについてのエッセイを書いてください」と。

Now all we have to do is wait for a few seconds.

今、私たちがしなければならないことは、数秒待つだけです。

There we go.

そこに行きます。

Our full ChatGPT answer.

私たちの完全なChatGPTの回答です。

And as you can see up here, we have the voice reply.

そして、ここで見ることができるように、音声の返信があります。

So if I hit play on this, Penguins, these flightless birds belong to the family's phenicidi and live in the southern hemisphere, mainly in Antarctica, though they can also be found in South Africa.

だから、これを再生ボタンを押せば、ペンギン、これらの飛べない鳥はフェニシダイ科に属し、主に南半球、特に南極大陸に生息していますが、南アフリカでも見つけることができます。

Okay, so now we're about to look at the most exciting part of this entire tutorial because here we're going to be getting a realistic voice greeting, My beloved master, from a site called 11 labs and using that with our script.

では、ここでこのチュートリアル全体で最もエキサイティングな部分を見ていきます。ここでは、11 labsというサイトから「私の愛しいご主人さま」というリアルな声の挨拶を取得し、それを私たちのスクリプトで使用する予定です。

So the phone is going to talk back in a realistic human-like sounding voice.

したがって、電話が人間のようなリアルな音声で応答することができます。

And all this is made possible by this company called ElevenLabs, which has these voices that are incredibly realistic.

そして、これがすべて11 Labsという会社によって可能になっています。彼らの声は非常にリアルです。

Just check this out for a second.

ちょっとこれを見てみてください。

So I'll just fill this out, and here you can pick the voice.

それでは、これを埋めて、ここで声を選ぶことができます。

So we'll just pick the default one and say generate.

では、デフォルトの声を選んで生成してみましょう。

Hey there, how are you doing, Igor?

こんにちは、イゴール、元気ですか?

This is a little too good to be real.

これはちょっと信じられないほど素晴らしいです。

Do you hear that?

聞こえますか?

Let's do that again.

もう一度やってみましょう。

Hey there, how are you doing, Igor?

こんにちは、イゴール、元気ですか?

This is a little too good to be real.

これはちょっと信じられないほど素晴らしいです。

And as I said, you can change this to Arnold.

そして私が言ったように、これをアーノルドに変えることもできます。

Let's just try that out.

それを試してみましょう。

Say generate.

「generate」と言ってください。

Hey there, how are you doing, Igor?

こんにちは、イゴールさん、お元気ですか?

This is a little too good to be real.

これはあまりにも良すぎて現実的ではありません。

Okay, so we're going to be using this for our app.

では、このアプリでこれを使用します。

How do we do that?

どうやってそれを行いますか?

Well, as you might have guessed, we need an API key, which you can simply get by going up here, profile.

まあ、お察しの通り、APIキーが必要です。これは、上部のプロファイルに移動して簡単に取得できます。

And then, you can copy your API key, which we'll be using in the script.

そして、スクリプトで使用するAPIキーをコピーすることができます。

0 to ElevenLabs chatbot, so just open that up, and we'll be inserting the ElevenLabs API key right here, and that is essentially it.

ElevenLabsチャットボットへの0からの挿入ですので、それを開き、ElevenLabsのAPIキーをここに挿入します。それで、基本的にはそれだけです。

Guys, look, we actually made this happen.

みんな、見てください、私たちは実際にこれを実現しました。

This would already work, but let me spend a few seconds explaining what's going on here.

これはすでに機能しますが、数秒間使い方を説明させてください。

Roughly, just like before, we have a little bit of code that extends this and makes ElevenLabs working here.

おおよそ、以前と同じように、これを拡張してElevenLabsを動作させる少しのコードがあります。

So, as you can see in both the text message and the voice message function, we have a few new lines down here that make 11 laps work.

ですので、テキストメッセージとボイスメッセージの関数の両方で、ElevenLabsを動作させるためのいくつかの新しい行があります。

It links it to the API key, and you actually get to pick the voice in here too, and that is hidden up here.

それはAPIキーに関連付けられ、実際にここで声も選ぶことができます。それはここに隠されています。

So, you can see the voice equals user.getvoices by name, and here you can pick it.

したがって、voice equals user.getvoices by name と書かれており、ここで選択することができます。

On the website, you will be able to test it and go through all the various voices, and once you find one that you like, you can copy the exact name that you see here and update your little script by changing this out to let's say Arnold, and there you go.

ウェブサイトでは、テストを行い、さまざまな声を試すことができ、気に入った声を見つけたら、ここで表示される正確な名前をコピーし、スクリプトを更新して、たとえば「アーノルド」と変更することができます。

That's really it.

それだけです。

If you want to understand this more in-depth, you can go over to their API reference to get a developer documentation.

これをより詳しく理解したい場合は、開発者ドキュメントを取得するために彼らのAPIリファレンスに移動することができます。

It's also that link I'll include below, but you can go in and look into the entire implementation.

それは以下に記載されているリンクですが、詳細な実装を調べることができます。

I won't be going for every single line in here, plus we've been copying over the stuff from before that has already been explained.

ここではすべての行について説明することはしませんし、既に説明された前の部分もコピーしてきました。

So, with all that being said and this thing being set up, we can go ahead and test this.

それでは、設定が完了したので、これをテストしてみましょう。

So, as you can see, we have the same role as before where the helpful assistant is going to be calling us Master every time, and let's just try it out.

ご覧の通り、以前と同じ役割を果たしています。助けになるアシスタントは毎回私たちを「マスター」と呼びますので、試してみましょう。

I'll hit play up here, and because we insert all the packages at the beginning, including 11 laps, remember when we ran the requirements, we installed ElevenLabs lib.

ここで再生ボタンを押しますが、パッケージはすべて先頭に挿入しているので、11つのラップを含めてすべてインストールされます。覚えていますか?前回の要件を実行したときにElevenLabsライブラリをインストールしました。

Now, we're going to put it to work by saying terminal new terminal, and then let's hit play, and it should be running.

では、新しいターミナルを作成して、再生ボタンを押してみましょう。それで実行されるはずです。

So, now all I need to do is pull up my phone, open up telegram, go into my voice Bots, and now I can record a voice message, and I should get one back.

では、今私はただ携帯電話を取り出して、テレグラムを開き、ボイスボットに入り、ボイスメッセージを録音して、返信を受け取ればいいだけです。

So, let's try this out.

さあ、これを試してみましょう。

Write me an essay about penguins.

ペンギンについてのエッセイを書いてください。

So, now we should see a transcription, write me an essay about penguins, and now as per usual, we need to wait for a little bit while GPT processes this, and the ElevenLabs generates the voice, but in a few seconds here, we should get an answer.

では、ここで「ペンギンについてのエッセイを書いてください」という転写が表示されるはずです。そして通常通り、GPTがこれを処理し、ElevenLabsが音声を生成するまで少し待つ必要がありますが、数秒後には回答が得られるはずです。

And there you go, as you can see, we got the GPT reply here, and above, we have the voice message that we can now play.

ご覧のように、ここでGPTの返信が表示され、上には再生できる音声メッセージがあります。

Greetings, my beloved Master.

愛しいマスター、こんにちは。

As requested, I will gladly provide you with an essay about penguins.

ご要望にお応えして、喜んでペンギンについてのエッセイを提供いたします。

Isn't that just incredible?

それはまさに信じられないことではありませんか?

And that's really how simple it is.

そして、それが本当に簡単な方法です。

All you gotta do is keep this running on your computer because this script makes it work.

このスクリプトを実行し続けておくだけで大丈夫です。これによって動作します。

Yes, you could alternatively host it, but that goes way beyond the scope of this tutorial.

もちろん、代わりにホストすることもできますが、それはこのチュートリアルの範囲を超えています。

I'll include a link in the description that shows you that too, but this is essentially it.

これについても説明するリンクを説明欄に含めますが、基本的にはこれだけです。

You can adjust the name, you can adjust the system message, and at the very least, you have the ultimate party trick in your pocket.

名前を調整したり、システムメッセージを調整したりすることができますし、最低限、ポケットに究極のパーティトリックがあります。

ChatGPT that you can talk to, it speaks back in any voice you pick, and as previously mentioned, you could go even further with this.

選んだ声で話しかけられるChatGPTです。以前にも言及したように、さらに進んでいくことも可能です。

You can teach it on specific data or give it a very specific role so it can help any business function even smoother.

特定のデータを教え込むこともできますし、非常に具体的な役割を与えることで、ビジネスの機能をさらにスムーズにサポートできます。

Additionally, you can automate away a bunch of processes, and now we offer all those services through the AI Advantage agency.

さらに、多くのプロセスを自動化することもできます。現在、それらのサービスをAI Advantageエージェンシーを通じて提供しています。

You can find more details on all that under this link, and again, if you haven't seen the first two episodes that explain the step-by-step to a complete beginner, then check out this playlist with all the videos in this series and how to build your very own chat spot by yourself without any coding knowledge required.

詳細については、このリンク先で詳細をご覧いただけます。また、まだ初心者向けのステップバイステップを説明した最初の2つのエピソードをご覧になっていない場合は、このシリーズのすべてのビデオと、コーディングの知識は必要ありませんで、自分自身で独自のチャットスポットを構築する方法について説明している再生リストをチェックしてください。

Why do you call me Master?

なぜ私をマスターと呼ぶのですか?

I thought Master has caused any confusion.

マスターという言葉が混乱を招いていると思いました。

Used as a sign of respect and formality.

敬意と礼儀の表れとして使用されます。

From here on out, call me Sensei.

これからは「先生」と呼んでください。

Understand, Sensei.

了解です、先生。

From now on, I will refer to you as Sensei.

これからはあなたを「先生」と呼ばせていただきます。

That is Sensei Igor for you.

それがイゴール先生です。

Up, Igor.

上、イゴール。

I will make sure to address you correctly in the future.

将来、正しくお呼びするようにいたします。

How may I be of service?

どのようにご奉仕いたしましょうか?

It works.

うまくいきました。


この記事が気に入ったらサポートをしてみませんか?