# amaaanmajid/hi-majid--a-voice-assistant architecture

> Architecture diagram of the GitHub repository amaaanmajid/hi-majid--a-voice-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amaaanmajid/hi-majid--a-voice-assistant
- Repository: https://github.com/amaaanmajid/hi-majid--a-voice-assistant

## Overview

This repository is a small, single-script voice assistant rather than a multi-service application. The entire system appears to live in `himajid.py`, with `README.md` documenting the runtime behavior and dependencies.

1. **Core role of the app**
   - “Hi Majid!” is a voice-activated conversational assistant.
   - Its main loop is: listen for speech, detect the wake word “Majid,” interpret the request, generate a response, speak it back, and repeat.

2. **Primary runtime shape**
   - The architecture is best described as a local, event-driven pipeline running in one Python process.
   - It uses background listening / control logic, then hands off to specialized subsystems for recognition, response generation, weather lookup, text-to-speech, and audio playback.

3. **Input boundary: microphone + speech recognition**
   - User input enters through the microphone.
   - `speech_recognition` converts raw audio into text.
   - This is the first major boundary in the system: spoken audio is transformed into transcribed text for downstream processing.

4. **Wake-word / trigger gate**
   - The assistant does not treat every utterance as a command.
   - It checks whether the transcript contains the trigger word “Majid.”
   - This gate separates casual background speech from actionable commands and controls when the assistant should respond.

5. **Command interpretation layer**
   - After wake-word detection, the transcript is classified into a few intent types:
     - greeting / small talk
     - identity questions like “what is your name”
     - weather requests
     - open-ended conversation
     - termination phrases like “that’s all”
   - This is the main decision point that routes work to either a local rule or an external service.

6. **LLM-backed conversation path**
   - For general conversation, the assistant delegates to Ollama, which serves a LLaMA-family model locally.
   - That makes the model inference boundary distinct from the rest of the app: the Python script orchestrates the interaction, while Ollama generates the natural-language reply.

7. **Weather integration path**
   - Weather requests are handled separately from open conversation.
   - The assistant extracts a city name from the command and calls the OpenWeatherMap API through `requests`.
   - This introduces the only explicit remote data dependency besides the LLM runtime, and it is used to inject live external data into the response.

8. **Response synthesis / text-to-speech**
   - Once a text response is chosen, `gtts` converts it into speech audio.
   - This is another important boundary: internal text is transformed into an audio file or audio stream suitable for playback.

9. **Audio output boundary**
   - `pygame` is used to play the generated speech through the speakers.
   - So the output path is: generated text → synthesized audio → speaker playback.

10. **Session control and looping**
   - The app continues in a listen/respond loop until a stop phrase is received.
   - Special phrases like “that’s all” act as state transitions back to idle listening.
   - This gives the assistant a simple conversational session model without a separate server or UI.

11. **Auxiliary behavior**
   - The README mentions logging interactions to a text file.
   - It also mentions initialization of audio queues, threading events, and hotkey/listener setup, which suggests the script uses concurrency to keep listening and playback responsive.

12. **Key external dependencies and what they mean architecturally**
   - `speech_recognition`: speech-to-text input layer.
   - `ollama`: local LLM inference backend.
   - `gtts`: text-to-speech generation.
   - `pygame`: audio playback.
   - `requests`: weather API client.
   - These dependencies define the system boundaries more than any internal module decomposition, because the repository is effectively a coordinator around them.

13. **Architecture summary for diagramming**
   - The clean diagram should show one Python application in the center.
   - On the left: microphone input into speech recognition.
   - In the middle: wake-word detection and intent routing.
   - On the right: two response sources, Ollama for general conversation and OpenWeatherMap for weather.
   - Then the response goes through gTTS and pygame to speakers.
   - A logging side path records interactions to disk.

14. **Overall characterization**
   - This is a local voice assistant with thin orchestration logic and several external capability boundaries.
   - It is not structured as a distributed system; the meaningful architecture is the flow of data through recognition, intent handling, external lookup/model inference, speech generation, and playback.

Main entry points: [`himajid.py`](https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/himajid.py) (Hi Majid), [`README.md`](https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Single-process assistant"]
  node_script["Hi Majid<br/>python app<br/>[himajid.py]"]
  node_mic(("Microphone<br/>audio input"))
  node_stt["Speech-to-text<br/>recognition"]
  node_wake{{"Wake word<br/>gate"}}
  node_router{{"Intent router<br/>classifier"}}
  node_chat["Conversation path<br/>llm flow"]
  node_ollama[("Ollama<br/>local LLM")]
  node_weather["Weather path<br/>api flow"]
  node_owm[("OpenWeatherMap<br/>remote API")]
  node_tts["Text-to-speech<br/>synthesis"]
  node_playback(("Speaker playback<br/>audio output"))
  node_log["Interaction log<br/>file log"]
  node_loop{{"Session loop<br/>control loop"}}
end

subgraph group_docs["Documentation"]
  node_readme["README<br/>docs<br/>[README.md]"]
end

node_readme -.->|"documents"| node_script
node_script -->|"listens"| node_mic
node_mic -->|"audio"| node_stt
node_stt -->|"transcript"| node_wake
node_wake -->|"enabled"| node_router
node_router -->|"general talk"| node_chat
node_router -->|"weather request"| node_weather
node_router -->|"stop phrase"| node_loop
node_chat -->|"generate"| node_ollama
node_weather -->|"fetch"| node_owm
node_ollama -->|"reply text"| node_tts
node_owm -->|"weather text"| node_tts
node_tts -->|"audio"| node_playback
node_playback -->|"done"| node_loop
node_script -.->|"records"| node_log
node_loop -->|"repeat"| node_script

click node_readme "https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/README.md"
click node_script "https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/himajid.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_script,node_mic,node_stt,node_wake,node_router,node_chat,node_ollama,node_weather,node_owm,node_tts,node_playback,node_log,node_loop toneBlue
class node_readme toneAmber
```

## Components

### Single-process assistant

Local voice assistant orchestration and external service boundaries

- [Hi Majid](https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/himajid.py): python app · Main orchestration script for the assistant · `himajid.py`
- **Microphone**: audio input · Captures spoken user input
- **Speech-to-text**: recognition · Transcribes audio into text
- **Wake word**: gate · Checks for the Majid trigger
- **Intent router**: classifier · Routes transcripts to greeting, weather, chat, or stop handling
- **Conversation path**: llm flow · Handles open-ended replies through the local model backend
- **Ollama**: local LLM · Generates general conversation responses
- **Weather path**: api flow · Fetches live weather for a requested city
- **OpenWeatherMap**: remote API · External weather data source
- **Text-to-speech**: synthesis · Converts response text into spoken audio
- **Speaker playback**: audio output · Plays synthesized speech through speakers
- **Interaction log**: file log · Records assistant interactions to disk
- **Session loop**: control loop · Keeps the assistant listening until a stop phrase ends the session

### Documentation

Repository notes and runtime description

- [README](https://github.com/amaaanmajid/hi-majid--a-voice-assistant/blob/main/README.md): docs · Runtime overview, setup, and dependency notes · `README.md`

## Connections

- README → Hi Majid: documents · Describes how the assistant runs and what it depends on
- Hi Majid → Microphone: listens · Starts from the microphone boundary
- Microphone → Speech-to-text: audio · Raw speech is transcribed into text
- Speech-to-text → Wake word: transcript · Text is checked for the Majid wake word
- Wake word → Intent router: enabled · Only triggered speech enters command handling
- Intent router → Conversation path: general talk · Open-ended requests go to conversational handling
- Intent router → Weather path: weather request · Weather queries are routed separately
- Intent router → Session loop: stop phrase · Termination phrases return the assistant to idle listening
- Conversation path → Ollama: generate · Delegates natural-language response generation to the local model backend
- Weather path → OpenWeatherMap: fetch · Calls the weather API for live data
- Ollama → Text-to-speech: reply text · Model output becomes speech text
- OpenWeatherMap → Text-to-speech: weather text · Fetched weather data is turned into a spoken response
- Text-to-speech → Speaker playback: audio · Synthesized speech is sent to speaker playback
- Speaker playback → Session loop: done · After playback, the assistant returns to listening
- Hi Majid → Interaction log: records · Interaction history is written to a text log
- Session loop → Hi Majid: repeat · The main script repeatedly cycles through listen and respond
