{"id":31890550,"url":"https://github.com/anshul21107/empathy-engine","last_synced_at":"2026-05-03T22:31:20.802Z","repository":{"id":315293037,"uuid":"1058910613","full_name":"Anshul21107/Empathy-Engine","owner":"Anshul21107","description":"Converts text into speech with emotion — adjusting tone, speed, and volume for happy, sad, or neutral expressions.","archived":false,"fork":false,"pushed_at":"2025-09-17T18:58:52.000Z","size":229,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-13T07:50:28.441Z","etag":null,"topics":["fastapi","python3","pyttsx3-text-to-speech","streamlit","textblob"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Anshul21107.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-17T18:03:58.000Z","updated_at":"2025-09-17T18:58:56.000Z","dependencies_parsed_at":"2025-09-17T20:50:30.004Z","dependency_job_id":"dedecc9e-52be-4bb9-8937-5ec76f26fd1b","html_url":"https://github.com/Anshul21107/Empathy-Engine","commit_stats":null,"previous_names":["anshul21107/empathy-engine"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Anshul21107/Empathy-Engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anshul21107%2FEmpathy-Engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anshul21107%2FEmpathy-Engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anshul21107%2FEmpathy-Engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anshul21107%2FEmpathy-Engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anshul21107","download_url":"https://codeload.github.com/Anshul21107/Empathy-Engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anshul21107%2FEmpathy-Engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32587816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","python3","pyttsx3-text-to-speech","streamlit","textblob"],"created_at":"2025-10-13T07:49:41.732Z","updated_at":"2026-05-03T22:31:20.360Z","avatar_url":"https://github.com/Anshul21107.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎙️ Empathy Engine  (Assignment)\n\nThis project is an **Emotion-Aware Text-to-Speech (TTS) system** that detects emotions from input text and generates **emotionally aligned speech**.  \nIt combines **sentiment analysis** with **speech synthesis parameters** (rate, volume, voice) to make the output sound more human-like and empathetic.  \n\n---\n\n## 🚀 Features\n- **Emotion Detection** → Uses `TextBlob` to analyze sentiment and map text into *happy*, *sad*, or *neutral* with intensity.  \n- **Dynamic Speech Synthesis** → Adjusts speech **rate**, **volume**, and **voice** based on detected emotion and intensity.  \n- **FastAPI Backend** → Exposes a `/speak` API endpoint to generate emotional speech.  \n- **Streamlit Frontend** → Simple UI for users to input text and listen to emotional speech.  \n- **Female Voice Support** → Configured `pyttsx3` to use a female voice (instead of default male).  \n\n---\n\n## 🛠️ Project Structure\n```\n.\n├── app.py              # FastAPI backend (API to generate speech)\n├── config.py           # Emotion mapping (rate, volume adjustments per emotion)\n├── emotion_detector.py # Emotion detection using TextBlob sentiment analysis\n├── streamlit_app.py    # Streamlit frontend UI\n├── tts_engine.py       # Text-to-Speech generation logic\n```\n\n---\n\n## ⚙️ How It Works\n1. **User Input** → Text is entered via Streamlit frontend.  \n2. **Emotion Detection** → `emotion_detector.py` uses sentiment polarity:  \n   - Positive → Happy 😃  \n   - Negative → Sad 😢  \n   - Neutral → Neutral 😐  \n   Intensity is scaled between 0 → 1.  \n3. **Parameter Mapping** → In `config.py`, each emotion has base values for:  \n   - Speech **rate** (words per minute)  \n   - Speech **volume** (loudness)  \n   - Variations depending on intensity  \n4. **Speech Synthesis** → `tts_engine.py` uses `pyttsx3` to generate speech:  \n   - Adjusts rate \u0026 volume dynamically  \n   - Selects a **female voice** (`voices[1].id`)  \n5. **API Response** → `app.py` streams back `.wav` audio to the frontend.  \n6. **Frontend Playback** → Streamlit displays detected emotion + plays audio.  \n\n---\n\n## ▶️ Usage\n\nFollow these steps to set up and run the project:\n\n### 1️⃣ Clone the Repository\n```bash\ngit clone https://github.com/Anshul21107/Empathy-Engine\ncd Empathy-Engine\n```\n\n### 2️⃣Create \u0026 Activate Virtual Environment\n```bash\npython -m venv venv\nvenv\\Scripts\\activate\n```\n\n### 3️⃣ Install Dependencies\n```bash\npip install -r requirements.txt\n```\n\n### 4️⃣Run Backend (FastAPI)\n```bash\npython app.py\n```\n### 5️⃣ Run Frontend (Streamlit)\n```bash\nstreamlit run streamlit_app.py\n```\n\n### Example\n- Input: `\"I am so excited about this new project!\"`  \n- Detected: Emotion = `happy`, Intensity ≈ `0.9`  \n- Output: Faster, louder, female-voiced audio with happy tone.  \n\n---\n\n## 📂 API Endpoint\n**POST** `/speak`  \n```json\n{\n  \"text\": \"Your input sentence here\"\n}\n```\n**Response**: WAV audio stream + headers:  \n- `X-Emotion`: Detected emotion  \n- `X-Intensity`: Emotion intensity  \n\n---\n\n## Points\n- Implemented **sentiment-based prosody control** (rate, volume, voice).  \n- Used **FastAPI for scalable backend** + **Streamlit for quick prototyping UI**.  \n- Showed ability to integrate **NLP + TTS + Web APIs**.  \n- Designed `EMOTION_MAP` for **realistic emotion simulation**.  \n- Extended TTS to **female voice selection** (instead of default male).  \n\n--- \n## 📸 Screenshots\n\n### 🔹 FastAPI Endpoint\n![FastAPI ](screenshots/fast-api.png)\n\n### 🔹 Streamlit UI\n![UI design](screenshots/streamlit-UI.png)\n\n\n## 🔊 Sample Audio Output\n\nHere’s an example of **emotionally generated speech of this text: \"I am deeply saddened by this unfortunate event. It's truly heartbreaking.\"**:\n\n🎧 [▶️ Listen to This Example](temp_audio.wav)\n\n\n---\n\n## 👨‍💻 Author\nDeveloped by **Anshul Katiyar**  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshul21107%2Fempathy-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshul21107%2Fempathy-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshul21107%2Fempathy-engine/lists"}