#๐Ÿ”’ Listening for audio on a tab

5 messages ยท Page 1 of 1 (latest)

unique dust
#

I get the error
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject1\main.py", line 58, in <module>
browser.close_browser()
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Browser' object has no attribute 'close_browser'
and my code is
from pychrome import Browser
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

Set the threshold decibel level

threshold_db = 30

Function to produce a loud beep

def beep():
print("Alert! Sound level reached.")
# Insert your code here to produce a loud beep

Function to check if sound level exceeds threshold and produce beep

def check_sound(message, data):
# Extract audio data from the message
audio_data = data['params'].get('audioBuffer')
if audio_data:
# Calculate the average intensity of the audio data
intensity = sum(abs(sample) for sample in audio_data) / len(audio_data)
volume_norm = intensity * 10
print(f"Current sound level: {volume_norm} dB")
if volume_norm > threshold_db:
beep()

Set up ChromeOptions to run headless

chrome_options = Options()
chrome_options.add_argument('--headless')

Start the Chrome browser

browser = Browser(url="http://127.0.0.1:9222")

try:
# Set up the ChromeDriver
driver = webdriver.Chrome(options=chrome_options)

# Open a webpage with audio content (replace with your desired URL)
driver.get('url')  # Replace with your desired URL

# Enable the Network domain
browser.network.enable()

# Listen for audio events
browser.network.on('AudioContext.addAudioBuffer', check_sound)

# Let it run indefinitely (you may modify or add conditions to exit the loop)
while True:
    time.sleep(1)

except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
# Close the browser
if driver:
driver.quit()
# Close the Chrome browser
browser.close_browser()

digital pecanBOT
#

@unique dust

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

unique dust
#

im trying to have it listen for audio on a tab

digital pecanBOT
#

@unique dust

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.