From 66f258f44ec1d4046b8a83b7a825cde94fb657c6 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Mon, 27 Dec 2021 18:33:11 -0500 Subject: [PATCH] Implemented command line SDR integration TODO: - Add commands to allow changing Freq --- bot.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bot.py b/bot.py index 0b7ae80..5ada06b 100644 --- a/bot.py +++ b/bot.py @@ -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)