An open API service indexing awesome lists of open source software.

https://github.com/michaelnabil230/ai-voice-assistant

AI Voice Assistant
https://github.com/michaelnabil230/ai-voice-assistant

ai edge flask python text-to-speech tts voice

Last synced: 6 days ago
JSON representation

AI Voice Assistant

Awesome Lists containing this project

README

          

# 🧠 AI Voice Assistant (Flask + OpenRouter + Edge TTS)

This project is an **AI-powered voice assistant** built with **Flask**, **OpenRouter (DeepSeek)** for AI responses, and **Edge TTS** for text-to-speech synthesis.
It allows users to type a message, receive an AI-generated reply, and listen to the response in **Arabic voice** using **Microsoft Edge Text-to-Speech**.

---

## πŸš€ Features

* πŸ€– **AI Chat via OpenRouter** β€” integrates DeepSeek model for intelligent responses.
* πŸ”Š **Text-to-Speech (TTS)** β€” converts AI replies to Arabic speech (`ar-SA-HamedNeural`).
* 🧩 **Flask Web App** β€” lightweight backend and simple frontend for interaction.
* πŸ’Ύ **Session-based chat history** β€” remembers previous conversation context.
* 🧠 **Custom System Prompt** β€” load behavior from `prompts/system.txt`.

---

## 🧱 Project Structure

```
project/
β”œβ”€β”€ app.py
β”œβ”€β”€ templates/
β”‚ └── index.html
β”œβ”€β”€ static/
β”‚ └── (generated audio files)
β”œβ”€β”€ prompts/
β”‚ └── system.txt
└── README.md
```

---

## βš™οΈ Requirements

* Python 3.9+
* `Flask`
* `edge-tts`
* `requests`
* `asyncio`

Install dependencies:

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

---

## πŸ”‘ Configuration

### 1. Environment Variables

Set your **OpenRouter API key** securely in the .env:

```
OPENROUTER_API_KEY="your-openrouter-api-key"
```

### 2. Create Prompt File

Create a `prompts/system.txt` file to define the assistant’s behavior, for example:

```
You are an AI assistant speaking in Arabic, helpful and professional.
Respond naturally and clearly.
```

---

## πŸ–₯️ Running the App

Run the Flask server:

```bash
python app.py
```

It will start the app on:

```
http://localhost:5151
```

---

## 🧠 API Endpoints

### `POST /speak`

**Description:**
Takes text input, sends it to OpenRouter for AI response, and generates a speech audio file.

**Request Form Data:**

| Key | Type | Description |
| ---- | ------ | --------------- |
| text | string | User input text |

**Response JSON:**

```json
{
"reply": "AI-generated text reply",
"audio_url": "/static/abc123.wav"
}
```

---

## 🧩 Voice Options

To list available voices:

```bash
edge-tts --list-voices
```

Then modify this line in `app.py`:

```python
communicate = edge_tts.Communicate(ai_response, "ar-SA-HamedNeural")
```

---

## 🧰 Notes

* Make sure the `static/` directory exists β€” it stores generated `.wav` files.
* The `session` is used to store chat history per user.
* You can replace `deepseek/deepseek-chat-v3.1:free` with any other OpenRouter model.

---

## πŸ“œ License

MIT License Β© 2025