{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n" ] } ], "source": [ "import queue\n", "\n", "# Create a FIFO queue\n", "q = queue.Queue()\n", "\n", "# Put items in the queue\n", "q.put(1)\n", "q.put(2)\n", "q.put(3)\n", "\n", "# Get items from the queue\n", "print(q.get()) # prints: 1\n", "print(q.get()) # prints: 2\n", "print(q.get()) # prints: 3" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Alice\n", "Bob\n", "Charlie\n" ] } ], "source": [ "import queue\n", "\n", "# Create a line\n", "line = queue.Queue()\n", "\n", "# People join the line\n", "line.put(\"Alice\") # Alice joins first\n", "line.put(\"Bob\") # Bob joins second\n", "line.put(\"Charlie\") # Charlie joins last\n", "\n", "# People leave the line\n", "print(line.get()) # Alice leaves first\n", "print(line.get()) # Bob leaves second\n", "print(line.get()) # Charlie leaves last" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ReturnPagedConfigs(page_number=0, page_size=10, total_pages=1, configs_page=[ReturnConfig(id='3bad47d1-bd76-48ed-b596-6c37a89b5570', version=0, evi_version='2', version_description='', name='2/17/2025, 03:24:50 PM', created_on=1739785191727, modified_on=1739785191727, prompt=ReturnPrompt(id='1d3c2d75-07fe-424b-97b7-04a8675a7318', version=0, version_type='FIXED', version_description='', name='prompt-phlhWtIJDokAdrbFERKnj', created_on=1739785190915, modified_on=1739785190915, text=''), voice=ReturnVoice(provider='HUME_AI', name=None, custom_voice=None), language_model=None, ellm_model=ReturnEllmModel(allow_short_responses=True), tools=[], builtin_tools=[], event_messages=ReturnEventMessageSpecs(on_new_chat=ReturnEventMessageSpec(enabled=False, text=None), on_inactivity_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_max_duration_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_resume_chat={'enabled': False, 'text': None}, on_disconnect_resume_chat={'enabled': False, 'text': None}), timeouts=ReturnTimeoutSpecs(inactivity=ReturnTimeoutSpec(enabled=True, duration_secs=120), max_duration=ReturnTimeoutSpec(enabled=True, duration_secs=1800)), webhooks=[])])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from hume.client import HumeClient\n", "import os \n", "client = HumeClient(\n", " api_key=os.getenv(\"HUME_API_KEY\"), # Defaults to HUME_API_KEY\n", ")\n", "client.empathic_voice.configs.list_configs()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error: 404 \n", " {\"code\":404, \"message\":\"Invalid URI Path\"}\n", " \n" ] } ], "source": [ "import requests\n", "import json\n", "\n", "\n", "\n", "# Function to connect to the EVI and send text for TTS\n", "def send_text_for_tts(text):\n", " url = 'https://api.hume.ai/v0/evi/chat'\n", " \n", " headers = {\n", " 'X-Hume-Api-Key': API_KEY,\n", " 'Content-Type': 'application/json'\n", " }\n", " \n", " payload = {\n", " 'configId': CONFIG_ID,\n", " 'text': text\n", " }\n", " \n", " response = requests.post(url, headers=headers, data=json.dumps(payload))\n", " \n", " if response.status_code == 200:\n", " print('Response:', response.json())\n", " else:\n", " print('Error:', response.status_code, response.text)\n", "\n", "# Example usage\n", "send_text_for_tts(\"Hello, this is a text to speech conversion using Hume.\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "ename": "ImportError", "evalue": "cannot import name 'HumeStreamClient' from 'hume' (/home/puzan/miniconda3/envs/conversai/lib/python3.12/site-packages/hume/__init__.py)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mhume\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m HumeStreamClient\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mhume\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mconfig\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m ProsodyConfig\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mrequests\u001b[39;00m\n", "\u001b[0;31mImportError\u001b[0m: cannot import name 'HumeStreamClient' from 'hume' (/home/puzan/miniconda3/envs/conversai/lib/python3.12/site-packages/hume/__init__.py)" ] } ], "source": [ "from hume import HumeStreamClient\n", "from hume.models.config import ProsodyConfig\n", "import requests\n", "\n", "API_KEY = \"your_hume_api_key\"\n", "\n", "def text_to_audio(text):\n", " client = HumeStreamClient(API_KEY)\n", " config = ProsodyConfig()\n", " \n", " print(\"Generating audio...\")\n", " response = client.submit([text], [config])\n", " \n", " for job in response:\n", " audio_url = job[\"results\"][\"prosody\"][\"audio_url\"]\n", " print(f\"Audio generated! You can download it here: {audio_url}\")\n", " return audio_url\n", "\n", "def download_audio(audio_url, output_file=\"output_audio.wav\"):\n", " print(\"Downloading audio...\")\n", " response = requests.get(audio_url)\n", " \n", " if response.status_code == 200:\n", " with open(output_file, \"wb\") as f:\n", " f.write(response.content)\n", " print(f\"Audio saved as {output_file}\")\n", " else:\n", " print(f\"Failed to download audio. Status code: {response.status_code}\")\n", "\n", "if __name__ == \"__main__\":\n", " text = \"Hello, this is a test of Hume's text-to-audio functionality.\"\n", " audio_url = text_to_audio(text)\n", " \n", " if audio_url:\n", " download_audio(audio_url)\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ReturnPagedConfigs(page_number=0, page_size=10, total_pages=1, configs_page=[ReturnConfig(id='9207e0c5-c75b-4b11-bbae-f5914614c652', version=0, evi_version='2', version_description='', name='2/19/2025, 03:27:23 PM', created_on=1739958144472, modified_on=1739958144472, prompt=ReturnPrompt(id='ba17413a-8251-4f39-8719-2d37bca6377c', version=0, version_type='FIXED', version_description='', name='prompt-LdpKTJOFO5tziv2EdiR6y', created_on=1739958143755, modified_on=1739958143755, text=''), voice=ReturnVoice(provider='HUME_AI', name='AURA', custom_voice=None), language_model=None, ellm_model=ReturnEllmModel(allow_short_responses=True), tools=[], builtin_tools=[], event_messages=ReturnEventMessageSpecs(on_new_chat=ReturnEventMessageSpec(enabled=False, text=None), on_inactivity_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_max_duration_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_resume_chat={'enabled': False, 'text': None}, on_disconnect_resume_chat={'enabled': False, 'text': None}), timeouts=ReturnTimeoutSpecs(inactivity=ReturnTimeoutSpec(enabled=True, duration_secs=120), max_duration=ReturnTimeoutSpec(enabled=True, duration_secs=1800)), webhooks=[]), ReturnConfig(id='3bad47d1-bd76-48ed-b596-6c37a89b5570', version=0, evi_version='2', version_description='', name='2/17/2025, 03:24:50 PM', created_on=1739785191727, modified_on=1739785191727, prompt=ReturnPrompt(id='1d3c2d75-07fe-424b-97b7-04a8675a7318', version=0, version_type='FIXED', version_description='', name='prompt-phlhWtIJDokAdrbFERKnj', created_on=1739785190915, modified_on=1739785190915, text=''), voice=ReturnVoice(provider='HUME_AI', name=None, custom_voice=None), language_model=None, ellm_model=ReturnEllmModel(allow_short_responses=True), tools=[], builtin_tools=[], event_messages=ReturnEventMessageSpecs(on_new_chat=ReturnEventMessageSpec(enabled=False, text=None), on_inactivity_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_max_duration_timeout=ReturnEventMessageSpec(enabled=False, text=None), on_resume_chat={'enabled': False, 'text': None}, on_disconnect_resume_chat={'enabled': False, 'text': None}), timeouts=ReturnTimeoutSpecs(inactivity=ReturnTimeoutSpec(enabled=True, duration_secs=120), max_duration=ReturnTimeoutSpec(enabled=True, duration_secs=1800)), webhooks=[])])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from hume.client import HumeClient \n", "# authenticate the synchronous client \n", "client = HumeClient(api_key=API_KEY) \n", "# list your configs \n", "client.empathic_voice.configs.list_configs()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sk_73eea9733ef8c80ebc700cd9f4432bc127406d116f7b61c2\n" ] }, { "ename": "ApiError", "evalue": "status_code: 401, body: {'detail': {'status': 'detected_unusual_activity', 'message': 'Unusual activity detected. Free Tier usage disabled. If you are using a proxy/VPN you might need to purchase a Paid Plan to not trigger our abuse detectors. Free Tier only works if users do not abuse it, for example by creating multiple free accounts. If we notice that many people try to abuse it, we will need to reconsider Free Tier altogether. \\nPlease play fair and purchase any Paid Subscription to continue.'}}", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mApiError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[5], line 18\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(API_KEY)\n\u001b[1;32m 10\u001b[0m audio \u001b[38;5;241m=\u001b[39m client\u001b[38;5;241m.\u001b[39mtext_to_speech\u001b[38;5;241m.\u001b[39mconvert(\n\u001b[1;32m 11\u001b[0m \n\u001b[1;32m 12\u001b[0m text\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe first move is what sets everything in motion.\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 15\u001b[0m output_format\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmp3_44100_128\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 16\u001b[0m )\n\u001b[0;32m---> 18\u001b[0m \u001b[43mplay\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/miniconda3/envs/conversai/lib/python3.12/site-packages/elevenlabs/play.py:19\u001b[0m, in \u001b[0;36mplay\u001b[0;34m(audio, notebook, use_ffmpeg)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mplay\u001b[39m(\n\u001b[1;32m 14\u001b[0m audio: Union[\u001b[38;5;28mbytes\u001b[39m, Iterator[\u001b[38;5;28mbytes\u001b[39m]], \n\u001b[1;32m 15\u001b[0m notebook: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m, \n\u001b[1;32m 16\u001b[0m use_ffmpeg: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 17\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(audio, Iterator):\n\u001b[0;32m---> 19\u001b[0m audio \u001b[38;5;241m=\u001b[39m \u001b[38;5;124;43mb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m notebook:\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", "File \u001b[0;32m~/miniconda3/envs/conversai/lib/python3.12/site-packages/elevenlabs/text_to_speech/client.py:201\u001b[0m, in \u001b[0;36mTextToSpeechClient.convert\u001b[0;34m(self, voice_id, text, enable_logging, optimize_streaming_latency, output_format, model_id, language_code, voice_settings, pronunciation_dictionary_locators, seed, previous_text, next_text, previous_request_ids, next_request_ids, use_pvc_as_ivc, apply_text_normalization, request_options)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m JSONDecodeError:\n\u001b[1;32m 200\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ApiError(status_code\u001b[38;5;241m=\u001b[39m_response\u001b[38;5;241m.\u001b[39mstatus_code, body\u001b[38;5;241m=\u001b[39m_response\u001b[38;5;241m.\u001b[39mtext)\n\u001b[0;32m--> 201\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ApiError(status_code\u001b[38;5;241m=\u001b[39m_response\u001b[38;5;241m.\u001b[39mstatus_code, body\u001b[38;5;241m=\u001b[39m_response_json)\n", "\u001b[0;31mApiError\u001b[0m: status_code: 401, body: {'detail': {'status': 'detected_unusual_activity', 'message': 'Unusual activity detected. Free Tier usage disabled. If you are using a proxy/VPN you might need to purchase a Paid Plan to not trigger our abuse detectors. Free Tier only works if users do not abuse it, for example by creating multiple free accounts. If we notice that many people try to abuse it, we will need to reconsider Free Tier altogether. \\nPlease play fair and purchase any Paid Subscription to continue.'}}" ] } ], "source": [ "from dotenv import load_dotenv\n", "from elevenlabs.client import ElevenLabs\n", "from elevenlabs import play\n", "import os\n", "\n", "load_dotenv()\n", "API_KEY=\"sk_73eea9733ef8c80ebc700cd9f4432bc127406d116f7b61c2\"\n", "client = ElevenLabs(api_key=API_KEY)\n", "print(API_KEY)\n", "audio = client.text_to_speech.convert(\n", "\n", " text=\"The first move is what sets everything in motion.\",\n", " voice_id=\"9BWtsMINqrJLrRacOk9x\",\n", " model_id=\"eleven_multilingual_v2\",\n", " output_format=\"mp3_44100_128\",\n", ")\n", "\n", "play(audio)\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sk_61687bfc187e7f403082805966a33bd4f147554a22427578\n" ] } ], "source": [ "print(os.getenv('ELEVENLABS_API_KEY'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conversai", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.8" } }, "nbformat": 4, "nbformat_minor": 2 }