#๐Ÿ”’ need help with audio

4 messages ยท Page 1 of 1 (latest)

crimson bluff
#

Hi, this is my script

import numpy as np
import sounddevice as sd
import librosa
import threading
import keyboard

gleaming_audio, _ = librosa.load("GleamingAudio.wav", sr=44100)

def detect_audio(stop_event,):
    stream = sd.InputStream(samplerate=44100, channels=2)
    stream.start()
    audio_record = []
    
    while not stop_event.is_set():
        frame, _ = stream.read(1)
        frame = np.mean(frame, axis=1)
        audio_record.extend(frame)
        if len(audio_record) == 84143:
            correlation = np.corrcoef(audio_record, gleaming_audio)[0, 1]
            if correlation > 0.5:
                print("Gleaming audio detected!")
            audio_record.pop(0)

def main():
    stop_event = threading.Event()
    print("Detecting gleaming audio...")
    detect_thread = threading.Thread(target=detect_audio, args=(stop_event,))
    detect_thread.start()
    keyboard.wait("0")
    stop_event.set()
    detect_thread.join()
    print("Gleaming audio detection stopped.")

if __name__ == "__main__":
    main()

the problem is that it doesnt detect even when i play the audio, does any1 know why?

stone blazeBOT
#

@crimson bluff

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.

stone blazeBOT
#

@crimson bluff

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.