{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "pip install gTTS\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "foIxTdl2Vg62", "outputId": "a77eb6fc-24b1-4f03-d867-51fec7d8b265" }, "execution_count": 21, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: gTTS in /usr/local/lib/python3.10/dist-packages (2.4.0)\n", "Requirement already satisfied: requests<3,>=2.27 in /usr/local/lib/python3.10/dist-packages (from gTTS) (2.31.0)\n", "Requirement already satisfied: click<8.2,>=7.1 in /usr/local/lib/python3.10/dist-packages (from gTTS) (8.1.7)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->gTTS) (3.3.0)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->gTTS) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->gTTS) (2.0.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->gTTS) (2023.7.22)\n" ] } ] }, { "cell_type": "code", "source": [ "from gtts import gTTS\n", "from IPython.display import Audio\n", "from io import BytesIO\n", "\n", "# Get user input\n", "text = input(\"Enter the text you want to convert to speech: \")\n", "\n", "# Create a gTTS object and get audio as bytes\n", "tts = gTTS(text)\n", "audio_bytes = BytesIO()\n", "tts.write_to_fp(audio_bytes)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "QTTQgFFbhPlW", "outputId": "95ee11b6-b915-49d8-8e8f-40967d3462d8" }, "execution_count": 24, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter the text you want to convert to speech: hi\n" ] } ] }, { "cell_type": "code", "source": [ "Audio(data=audio_bytes.getvalue())\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 75 }, "id": "TuS0xMmWhSN1", "outputId": "4d793689-4d31-4eda-8027-b6f58d80d0c2" }, "execution_count": 25, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "" ], "text/html": [ "\n", " \n", " " ] }, "metadata": {}, "execution_count": 25 } ] } ] }