顧客向けの音声応答を作成する

OpenAI APIで学ぶマルチモーダルシステム

James Chapman

Curriculum Manager, DataCamp

ケーススタディの計画

$$

$$

  • 応答の翻訳

$$

  • テキストを音声に変換

$$

ケーススタディの計画

OpenAI APIで学ぶマルチモーダルシステム

使用する変数

$$

検出された言語
print(language)
uk

$$

生成された応答
print(chatbot_reply)

チャットボットの応答

OpenAI APIで学ぶマルチモーダルシステム

応答の翻訳

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": f"""Translate the following text 
        from English to country code {language}. Only return the translated text!"""},
        {"role": "user", "content": chatbot_reply}
             ],
    max_completion_tokens=500)
OpenAI APIで学ぶマルチモーダルシステム

応答の翻訳

# Extract and print the translated response
translated_reply = response.choices[0].message.content
print(translated_reply)

翻訳結果

OpenAI APIで学ぶマルチモーダルシステム

テキスト読み上げ(TTS)

response = client.audio.speech.create(
    model="gpt-4o-mini-tts",
    voice="onyx",
    input=translated_reply)

response.stream_to_file("audio_reply.mp3")

バーチャルアシスタントとして描かれた Onyx の声。

OpenAI APIで学ぶマルチモーダルシステム

ケーススタディの振り返り

ケーススタディ - 全体

OpenAI APIで学ぶマルチモーダルシステム

次のステップ

チャットボットにメモリを追加

OpenAI APIで学ぶマルチモーダルシステム

練習しましょう!

OpenAI APIで学ぶマルチモーダルシステム

Preparing Video For Download...