]> git.0d.be Git - botaradio.git/commitdiff
chore: add a debug command 'rtrms' to display current rms of the speech in the consol...
authorTerry Geng <gengyanda@gmail.com>
Mon, 2 Mar 2020 13:54:13 +0000 (21:54 +0800)
committerTerry Geng <gengyanda@gmail.com>
Mon, 2 Mar 2020 13:54:13 +0000 (21:54 +0800)
command.py
mumbleBot.py

index a807df71a368ad54fd3415b67a6fc88e8cd12c3d..70b0154ae37043323d0a3bff65fdf173bdee4313 100644 (file)
@@ -54,6 +54,9 @@ def register_all_commands(bot):
     bot.register_command(constants.commands('mode'), cmd_mode)
     bot.register_command(constants.commands('drop_database'), cmd_drop_database)
 
+    # Just for debug use
+    bot.register_command('rtrms', cmd_real_time_rms)
+
 def send_multi_lines(bot, lines, text):
     global log
 
@@ -762,10 +765,13 @@ def cmd_mode(bot, user, text, command, parameter):
             var.playlist.randomize()
             bot.launch_music(0)
 
-
 def cmd_drop_database(bot, user, text, command, parameter):
     global log
 
     var.db.drop_table()
     var.db = Database(var.dbfile)
     bot.send_msg(constants.strings('database_dropped'), text)
+
+# Just for debug use
+def cmd_real_time_rms(bot, user, text, command, parameter):
+    bot._display_rms = not bot._display_rms
index 4ca7a3dcb51c68d599d26e5c4563ac1da1638fa2..8ce8fa7bcfbc28cf52e73d71bb4a9c62c088c8a0 100644 (file)
@@ -183,6 +183,10 @@ class MumbleBot:
                                                self.ducking_sound_received)
             self.mumble.set_receive_sound(True)
 
+        # Debug use
+        self._display_rms = False
+        self._max_rms = 0
+
     # Set the CTRL+C shortcut
     def ctrl_caught(self, signal, frame):
 
@@ -590,6 +594,7 @@ class MumbleBot:
         if self.on_ducking and self.ducking_release < time.time():
             self._clear_pymumble_soundqueue()
             self.on_ducking = False
+            self._max_rms = 0
 
         if delta > 0.001:
             if self.is_ducking and self.on_ducking:
@@ -600,7 +605,16 @@ class MumbleBot:
         self.last_volume_cycle_time = time.time()
 
     def ducking_sound_received(self, user, sound):
-        if audioop.rms(sound.pcm, 2) > self.ducking_threshold:
+        rms = audioop.rms(sound.pcm, 2)
+        self._max_rms = max(rms, self._max_rms)
+        if self._display_rms:
+            if rms < self.ducking_threshold:
+                print('%6d/%6d  ' % (rms, self._max_rms) + '-'*int(rms/200), end='\r')
+            else:
+                print('%6d/%6d  ' % (rms, self._max_rms) + '-'*int(self.ducking_threshold/200) \
+                      + '+'*int((rms - self.ducking_threshold)/200), end='\r')
+
+        if rms > self.ducking_threshold:
             if self.on_ducking is False:
                 self.log.debug("bot: ducking triggered")
                 self.on_ducking = True