# awaazai/freeswitch_modules architecture

> Architecture diagram of the GitHub repository awaazai/freeswitch_modules, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/awaazai/freeswitch_modules
- Repository: https://github.com/awaazai/freeswitch_modules

## Overview

1. **What this repo is**
   This is a collection of **FreeSWITCH loadable modules** that extend the media server with cloud speech capabilities: real-time transcription, text-to-speech, audio streaming/forking, VAD, and a few related utilities. The modules are mainly intended for **drachtio-fsmrf**-based apps, but they integrate at the FreeSWITCH module boundary and can be used in generic FreeSWITCH deployments.

2. **Primary runtime boundary**
   The architectural center is **FreeSWITCH itself**. Each module is a plugin loaded into FreeSWITCH and invoked through FreeSWITCH’s module/API/event hooks. The repo does not contain a standalone server; instead, it adds capabilities inside the telephony/media runtime.

3. **Main subsystem families**
   The modules cluster into a few functional families:
   - **Transcription modules**: `mod_google_transcribe`, `mod_deepgram_transcribe`, `mod_aws_transcribe`, `mod_aws_transcribe_ws`, `mod_azure_transcribe`, `mod_assemblyai_transcribe`, `mod_ibm_transcribe`, `mod_nuance_transcribe`, `mod_soniox_transcribe`, `mod_verbio_transcribe`, `mod_bodhi_transcribe`, `mod_cobalt_transcribe`, `mod_jambonz_transcribe`, `mod_nvidia_transcribe`
   - **TTS modules**: `mod_google_tts`, `mod_deepgram_tts`, `mod_rimelabs_tts`, `mod_verbio_tts`, `mod_whisper_tts`, `mod_custom_tts`
   - **Media/audio utilities**: `mod_audio_fork`, `mod_vad_detect`, `mod_dub`
   - **Conversation/NLU integration**: `mod_dialogflow`
   - **Vendor-specific glue/protocol support**: several `grpc_protobuf/*` trees and FreeSWITCH config patches

4. **Common implementation pattern**
   Most modules follow the same internal layering:
   - A **C module entrypoint** (`mod_*.c`) that FreeSWITCH loads
   - One or more **C++ glue layers** (`*_glue.cpp/.h`) that wrap the vendor SDK or protocol
   - A small set of shared helpers such as `audio_pipe`, `parser`, `simple_buffer`, and sometimes `base64`, `vector_math`, or `crc`
   This separation keeps the FreeSWITCH-facing code thin while isolating vendor-specific networking and serialization logic in the glue layer.

5. **How audio flows through the system**
   The dominant data flow is:
   **FreeSWITCH channel audio -> module capture/pipe/buffer -> vendor SDK or streaming API -> transcription/TTS result -> FreeSWITCH callbacks/events/API response**
   For transcription, audio is usually streamed out of the call leg in near real time. For TTS, text or synthesis requests are sent to the provider and the returned audio is fed back into FreeSWITCH’s TTS or playback path. Modules like `mod_audio_fork` and `mod_dub` are about moving or transforming audio before it reaches the external service.

6. **Streaming and transport choices**
   Different vendors use different wire protocols, and the repo mirrors that:
   - **gRPC** for Google/other gRPC-based services and the protobuf-backed modules
   - **WebSockets** for some streaming providers, including the AWS WebSocket variant and `mod_audio_fork`
   - **HTTP/SDK-based integrations** for providers whose official SDKs are wrapped directly
   The transport choice is not abstracted away globally; each module owns its own protocol adapter.

7. **Special media-processing components**
   `mod_audio_fork` is the clearest “media fan-out” component: it captures audio and forwards it out over WebSockets, with local buffering and DSP helpers. `mod_dub` appears to be a playback/overlay/transcoding-oriented media module, with file/HTTP audio sources and MP3 decode support. `mod_vad_detect` is a lighter utility module that detects voice activity rather than forwarding to a cloud service.

8. **FreeSWITCH customization and packaging**
   The `conf/` directory contains **FreeSWITCH config overlays, patches, service files, and build extras**. There are patches against FreeSWITCH core/media code and module lists, which indicates some modules require a **custom-built FreeSWITCH** rather than a stock install. The README calls out that Google and gRPC-based modules need FreeSWITCH built with **gRPC support**, and `mod_audio_fork` needs **libwebsockets**.

9. **Protocol schema artifacts**
   The `grpc_protobuf/` tree vendors multiple vendor API definitions:
   - Cobalt Speech gRPC API
   - Nuance ASR gRPC API
   - NVIDIA Riva gRPC API
   - Soniox ASR gRPC API
   These protobufs are part of the build-time contract for the gRPC-based modules. They define the request/response and streaming message boundaries between FreeSWITCH-side code and the external speech services.

10. **Examples and integration points**
   The `examples/` directory shows how the modules are consumed in practice:
   - Node.js examples for audio fork, AWS transcription, Google transcription/TTS, Dialogflow, and a WebSocket server
   - A Lua test/example
   - A default JSON config
   These examples are not core runtime components, but they document the expected orchestration from an application layer, especially for drachtio-style call control.

11. **Configuration and credentials**
   Some modules rely on external credentials or config files rather than hardcoded settings. The README specifically mentions `GOOGLE_APPLICATION_CREDENTIALS` for Google modules. Several modules also ship their own FreeSWITCH XML snippets under `conf/` or module-specific `conf/` directories, showing that deployment is partly controlled through FreeSWITCH config, not only through runtime API calls.

12. **Architecture summary for a diagram**
   A clear diagram should show:
   - **FreeSWITCH core** in the center
   - Multiple **pluggable modules** attached to it
   - A split between **audio capture/processing** and **vendor protocol adapters**
   - Outbound links from modules to **cloud speech/TTS/NLU providers**
   - A build/config layer made of **FreeSWITCH patches, XML config, and protobuf definitions**
   - Optional **application consumers** such as drachtio/fsrmf or the example Node/Lua scripts

Main entry points: [`examples`](https://github.com/awaazai/freeswitch_modules/tree/main/examples) (Examples), [`modules`](https://github.com/awaazai/freeswitch_modules/tree/main/modules) (TTS mods), [`conf`](https://github.com/awaazai/freeswitch_modules/tree/main/conf) (FreeSWITCH config), [`modules/mod_google_tts`](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_google_tts) (Google TTS)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_freeswitch["FreeSWITCH<br/>telephony runtime"]
  node_transcribe_family["Transcribe mods<br/>module family"]
  node_tts_family["TTS mods<br/>module family"]
  node_media_family["Media utils<br/>module family"]
  node_dialogflow_mod["Dialogflow<br/>nlu module"]
  node_google_transcribe["Google STT<br/>grpc transcribe module"]
  node_aws_transcribe_ws["AWS WS<br/>websocket transcribe module"]
  node_audio_fork["Audio fork<br/>media streaming module"]
  node_vad_detect["VAD detect<br/>audio utility"]
  node_dub["Dub<br/>audio playback module"]
  node_google_tts["Google TTS<br/>tts module"]
  node_deepgram_tts["Deepgram TTS<br/>tts module"]
  node_custom_tts["Custom TTS<br/>tts module"]
end

subgraph group_build["Build & config"]
  node_protobufs["gRPC protos<br/>schema bundle"]
  node_conf["FreeSWITCH config<br/>patch/config bundle"]
end

subgraph group_examples["Examples"]
  node_examples_dir["Examples<br/>integration samples"]
end

subgraph group_external["Cloud services"]
  node_cloud_speech(("Cloud speech<br/>vendor APIs"))
  node_drachtio_apps(("App layer<br/>consumer apps"))
end

node_freeswitch -->|"loads"| node_transcribe_family
node_freeswitch -->|"loads"| node_tts_family
node_freeswitch -->|"loads"| node_media_family
node_freeswitch -->|"loads"| node_dialogflow_mod
node_transcribe_family -->|"includes"| node_google_transcribe
node_transcribe_family -->|"includes"| node_aws_transcribe_ws
node_tts_family -->|"includes"| node_google_tts
node_tts_family -->|"includes"| node_deepgram_tts
node_tts_family -->|"includes"| node_custom_tts
node_media_family -->|"includes"| node_audio_fork
node_media_family -->|"includes"| node_vad_detect
node_media_family -->|"includes"| node_dub
node_google_transcribe -->|"uses"| node_cloud_speech
node_aws_transcribe_ws -->|"uses"| node_cloud_speech
node_google_tts -->|"uses"| node_cloud_speech
node_deepgram_tts -->|"uses"| node_cloud_speech
node_custom_tts -->|"adapts"| node_cloud_speech
node_dialogflow_mod -->|"uses"| node_cloud_speech
node_protobufs -->|"schemas"| node_transcribe_family
node_conf -->|"patches"| node_freeswitch
node_conf -->|"enables"| node_audio_fork
node_conf -->|"enables"| node_google_tts
node_examples_dir -->|"demonstrates"| node_audio_fork
node_examples_dir -->|"demonstrates"| node_google_transcribe
node_examples_dir -->|"demonstrates"| node_google_tts
node_examples_dir -->|"demonstrates"| node_aws_transcribe_ws
node_examples_dir -->|"demonstrates"| node_dialogflow_mod
node_examples_dir -->|"targets"| node_drachtio_apps
node_freeswitch -->|"configured by"| node_conf

click node_transcribe_family "https://github.com/awaazai/freeswitch_modules/tree/main/modules"
click node_tts_family "https://github.com/awaazai/freeswitch_modules/tree/main/modules"
click node_media_family "https://github.com/awaazai/freeswitch_modules/tree/main/modules"
click node_dialogflow_mod "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_dialogflow"
click node_google_transcribe "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_google_transcribe"
click node_aws_transcribe_ws "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_aws_transcribe_ws"
click node_audio_fork "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_audio_fork"
click node_vad_detect "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_vad_detect"
click node_dub "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_dub"
click node_google_tts "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_google_tts"
click node_deepgram_tts "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_deepgram_tts"
click node_custom_tts "https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_custom_tts"
click node_protobufs "https://github.com/awaazai/freeswitch_modules/tree/main/grpc_protobuf"
click node_conf "https://github.com/awaazai/freeswitch_modules/tree/main/conf"
click node_examples_dir "https://github.com/awaazai/freeswitch_modules/tree/main/examples"

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_freeswitch,node_transcribe_family,node_tts_family,node_media_family,node_dialogflow_mod,node_google_transcribe,node_aws_transcribe_ws,node_audio_fork,node_vad_detect,node_dub,node_google_tts,node_deepgram_tts,node_custom_tts toneBlue
class node_protobufs,node_conf toneAmber
class node_examples_dir toneMint
class node_cloud_speech,node_drachtio_apps toneRose
```

## Components

### Runtime

FreeSWITCH-loaded media modules and their internal families

- **FreeSWITCH**: telephony runtime · Host media server that loads and invokes the modules
- [Transcribe mods](https://github.com/awaazai/freeswitch_modules/tree/main/modules): module family · Streaming speech-to-text plugins for multiple vendors · `modules`
- [TTS mods](https://github.com/awaazai/freeswitch_modules/tree/main/modules): module family · Text-to-speech plugins for provider APIs and SDKs · `modules`
- [Media utils](https://github.com/awaazai/freeswitch_modules/tree/main/modules): module family · Audio routing, fork, VAD, and playback-oriented modules · `modules`
- [Dialogflow](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_dialogflow): nlu module · Conversation integration module built around Google/Dialogflow glue · `modules/mod_dialogflow`
- [Google STT](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_google_transcribe): grpc transcribe module · Google transcription module with multiple glue versions · `modules/mod_google_transcribe`
- [AWS WS](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_aws_transcribe_ws): websocket transcribe module · AWS transcription variant that streams over WebSockets · `modules/mod_aws_transcribe_ws`
- [Audio fork](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_audio_fork): media streaming module · Captures call audio and forwards it out to external consumers · `modules/mod_audio_fork`
- [VAD detect](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_vad_detect): audio utility · Voice activity detection module · `modules/mod_vad_detect`
- [Dub](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_dub): audio playback module · Media overlay and source handling module with decode support · `modules/mod_dub`
- [Google TTS](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_google_tts): tts module · Google text-to-speech plugin · `modules/mod_google_tts`
- [Deepgram TTS](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_deepgram_tts): tts module · Deepgram text-to-speech plugin · `modules/mod_deepgram_tts`
- [Custom TTS](https://github.com/awaazai/freeswitch_modules/tree/main/modules/mod_custom_tts): tts module · Pluggable text-to-speech bridge for custom providers · `modules/mod_custom_tts`

### Build & config

Patches, XML overlays, and protobuf contracts

- [gRPC protos](https://github.com/awaazai/freeswitch_modules/tree/main/grpc_protobuf): schema bundle · Vendored protobuf contracts for gRPC-based speech modules · `grpc_protobuf`
- [FreeSWITCH config](https://github.com/awaazai/freeswitch_modules/tree/main/conf): patch/config bundle · Patches, XML overlays, service files, and build extras · `conf`

### Examples

Consumer scripts and integration samples

- [Examples](https://github.com/awaazai/freeswitch_modules/tree/main/examples): integration samples · Node.js and Lua scripts showing module usage · `examples`

### Cloud services

Vendor speech, TTS, and NLU endpoints

- **Cloud speech**: vendor APIs · External STT, TTS, and NLU providers
- **App layer**: consumer apps · Call-control applications that orchestrate FreeSWITCH modules

## Connections

- FreeSWITCH → Transcribe mods: loads · FreeSWITCH loads transcription plugins as modules
- FreeSWITCH → TTS mods: loads · FreeSWITCH loads TTS plugins as modules
- FreeSWITCH → Media utils: loads · FreeSWITCH loads media utility plugins as modules
- FreeSWITCH → Dialogflow: loads · FreeSWITCH loads the Dialogflow module
- Transcribe mods → Google STT: includes · Representative Google streaming transcription implementation
- Transcribe mods → AWS WS: includes · Representative AWS WebSocket transcription implementation
- TTS mods → Google TTS: includes · Google TTS implementation
- TTS mods → Deepgram TTS: includes · Deepgram TTS implementation
- TTS mods → Custom TTS: includes · Custom TTS integration point
- Media utils → Audio fork: includes · Audio fan-out and streaming component
- Media utils → VAD detect: includes · Voice activity detection component
- Media utils → Dub: includes · Playback and overlay component
- Google STT → Cloud speech: uses · Connects to Google's speech APIs
- AWS WS → Cloud speech: uses · Connects to AWS streaming speech APIs
- Google TTS → Cloud speech: uses · Connects to Google TTS services
- Deepgram TTS → Cloud speech: uses · Connects to Deepgram TTS services
- Custom TTS → Cloud speech: adapts · Custom provider bridge
- Dialogflow → Cloud speech: uses · Connects to Dialogflow-related Google services
- gRPC protos → Transcribe mods: schemas · Build-time gRPC contracts consumed by speech modules
- FreeSWITCH config → FreeSWITCH: patches · Config overlays and patches for FreeSWITCH integration
- FreeSWITCH config → Audio fork: enables · Deployment and module configuration support
- FreeSWITCH config → Google TTS: enables · Module-specific FreeSWITCH XML config
- Examples → Audio fork: demonstrates · Example app usage of audio fork
- Examples → Google STT: demonstrates · Example app usage of Google transcription
- Examples → Google TTS: demonstrates · Example app usage of Google TTS
- Examples → AWS WS: demonstrates · Example app usage of AWS transcription
- Examples → Dialogflow: demonstrates · Example app usage of Dialogflow integration
- Examples → App layer: targets · Scripts are meant to be driven from call-control apps
- FreeSWITCH → FreeSWITCH config: configured by · Modules depend on FreeSWITCH build/config overlays
