Implemented command line SDR integration

TODO:
- Add commands to allow changing Freq
This commit is contained in:
Logan Cusano
2021-12-27 18:33:11 -05:00
parent 9a36f56d28
commit 66f258f44e

26
bot.py
View File

@@ -1,4 +1,5 @@
import os
import subprocess
import discord
import sound
from discord.ext import commands
@@ -18,6 +19,12 @@ class Bot(commands.Bot):
self.Default_Mention_Group = kwargs['Mention_Group']
self.Devices_List = sound.query_devices().items()
self.sdr_process = None
self.system_os_type = None
# Set linux or windows
self.check_os_type()
self.add_commands()
self.check_for_modules()
@@ -47,6 +54,8 @@ class Bot(commands.Bot):
voice_connection = await channel.connect()
voice_connection.play(discord.PCMAudio(stream))
self.start_sdr()
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening,
name="the airwaves"),
status=discord.Status.online)
@@ -99,3 +108,20 @@ class Bot(commands.Bot):
except Exception as e:
print(e)
return False
def check_os_type(self):
if os.name == 'nt':
self.system_os_type = 'Windows'
else:
self.system_os_type = 'Linux'
def start_sdr(self, freq="104.7M", gain=40, squelch=0, sample_rate="200k", mode="wbfm"):
possible_modes = ['wbfm', 'fm']
if type(freq) == str:
# Single freq sent
if self.sdr_process:
self.sdr_process.terminate()
self.sdr_process = subprocess.Popen(["rtl_fm", f"-M {mode}", f"-f {freq}", f"-g {gain}",
f"-l {squelch}", f"-s {sample_rate}",
f"| play -t raw -r 32k -es -b 16 -c 1 -V1 -"], shell=True)