"This should include a Gradio UI, streaming, use of the system prompt to add expertise, and the ability to switch between models. Bonus points if you can demonstrate use of a tool!\n",
"\n",
"The assistant will transform your spoken English to text, then translate it German and speak it out."
"The assistant will transform your spoken English to text, then translate it German and speak it out. The image on the UI is just decoration. This exercise was created on MacOS, Python 3.13."
]
},
{
@ -28,12 +28,13 @@
"# Install first PortAudio, in MacOS\n",
"# brew install portaudio\n",
"\n",
"\n",
"!pip install openai speechrecognition pyaudio\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "dcae50aa",
"metadata": {},
"outputs": [],
@ -70,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"id": "c5caad24",
"metadata": {},
"outputs": [],
@ -89,24 +90,13 @@
"outputs": [],
"source": [
"import speech_recognition as sr\n",
"from pydub import AudioSegment\n",
"from pydub.playback import play\n",
"import base64\n",
"from io import BytesIO\n",
"from PIL import Image\n",
"\n",
"\n",
"def recognize_speech():\n",
" recognizer = sr.Recognizer()\n",
" with sr.Microphone() as source:\n",
" print(\"Say something...\")\n",
" audio = recognizer.listen(source)\n",
" try:\n",
" text = recognizer.recognize_google(audio)\n",
" print(f\"You said: {text}\")\n",
" return text\n",
" except sr.UnknownValueError:\n",
" print(\"Google Speech Recognition could not understand audio\")\n",
" return None\n",
" except sr.RequestError as e:\n",
" print(f\"Could not request results from Google Speech Recognition service; {e}\")\n",