Skip to content

Script to check if audio is played #248

Description

@nicolae-stroncea

I want to check is I am playing any audio on my PC(music, podcasts, from video, etc).

Here is the script for it:

import sounddevice as sd
import numpy as np

duration = 10
fs = 44100
myrecording = sd.rec(int(duration*fs), samplerate=fs, channels=2)
print(np.count_nonzero(myrecording > 0))

Currently my assumption is that if no audio is playing, then all elements of numpy array will be <=0. Is this correct?

This code is also listening in on the microphone, whilst I strictly want to record audio being played directly from the PC. Is it possible to only check for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions