Skip to content

WilleLX1/mic2discord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Mic Streaming Bot (Windows)

A low-latency Discord bot for streaming live microphone audio into a voice channel on Windows using FFmpeg (DirectShow) and @discordjs/voice. The bot supports listing microphones, selecting by index, hot-swapping devices while streaming, and start/stop controls—all without additional audio routing software.

Note: Desktop/system audio streaming is not included in this version. This bot streams microphone input only via DirectShow.


Features

  • 🎙️ Live microphone streaming to Discord voice channels
  • 🔁 Hot-swap microphones while streaming (no reconnect required)
  • 📋 List all DirectShow audio devices with indices
  • ⚡ Low-latency FFmpeg capture tuned for Windows
  • 🧠 Safe start/stop lifecycle (no orphan FFmpeg processes)

Requirements

  • Windows 10/11
  • Node.js v18+ (tested with Node 22)
  • FFmpeg with DirectShow support (in PATH)
  • Discord Bot Token

Required npm packages

  • discord.js
  • @discordjs/voice
  • @discordjs/opus
  • prism-media

Installation

npm init -y
npm install discord.js @discordjs/voice @discordjs/opus prism-media

Ensure ffmpeg.exe is accessible:

ffmpeg -version

Configuration

1. Set your Discord bot token

Temporary (current terminal only):

$env:DISCORD_TOKEN="YOUR_BOT_TOKEN_HERE"

Permanent (recommended):

  • System Properties → Environment Variables
  • Add User Variable:
    • Name: DISCORD_TOKEN
    • Value: your bot token

Restart your terminal after setting permanently.


2. (Optional) Set a default microphone

Edit this line in index.js to match one of your DirectShow mic names:

let selectedMic = "Microphone (3- USB Audio CODEC )";

You can always change it at runtime with commands.


Running the Bot

From the project directory:

node index.js

You should see:

Logged in as YourBotName#1234

Discord Commands

!mics

Lists all available DirectShow microphone devices with indices.

Example output:

0: Microphone (USB Audio CODEC)
1: Microphone (HyperX Cloud Flight Wireless)
2: Microphone (NVIDIA Broadcast)

!mic <index>

Selects a microphone by index.

  • If not streaming: sets the mic for next start
  • If already streaming: hot-swaps the mic live

Example:

!mic 2

!micstart

Joins the voice channel you are currently in and starts streaming the selected microphone.


!micstop

Stops the microphone stream and leaves the voice channel.


!micstatus

Shows whether the mic stream is currently running and which device is selected.


FFmpeg Device Verification

To verify FFmpeg can see your microphones:

ffmpeg -list_devices true -f dshow -i dummy

Look for entries marked (audio) and ensure the device name matches exactly.


Latency Tuning

The FFmpeg pipeline is already optimized for low latency using:

  • -fflags nobuffer
  • -flags low_delay
  • -probesize 32
  • -analyzeduration 0
  • -rtbufsize 16M

Typical end-to-end latency is sub-second on most systems.


Known Limitations

  • Microphone audio only (no system/desktop audio in this version)
  • Windows-only (uses DirectShow)
  • One active voice stream per bot instance

Security & Privacy

  • Only stream audio you have permission to broadcast
  • Inform users in the voice channel when live audio is being relayed
  • The bot does not record or store audio

Troubleshooting

Bot joins but no audio

  • Ensure Windows microphone permissions allow desktop apps
  • Check the mic is not in exclusive mode
  • Verify the device name exactly matches FFmpeg output

Opus errors on startup

Ensure @discordjs/opus is installed:

npm install @discordjs/opus

License

MIT — use, modify, and distribute freely.


If you want to extend this project with desktop audio, mixing, push-to-talk, or per-role permissions, this codebase is a solid foundation to build on.

About

Stream live microphone audio into Discord voice channels with low latency and hot-swappable devices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors