bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
689 stars 70 forks source link

Assertion Crash #94

Open nicolae-stroncea opened 4 years ago

nicolae-stroncea commented 4 years ago

I'm running this on Fedora 32.

I occasionally get this error: Assertion 's' failed at pulse/stream.c:1411.

This is the code I'm running:

#!/usr/bin/env python
import soundcard as sc
import numpy as np

'''Get a microphone from a speaker, not the actual microphone'''
def getMic():
    mic = None
    mics = sc.all_microphones(include_loopback=True)
    for a_mic in mics:
        if(a_mic.isloopback):
            mic = a_mic
            break
    return mic

def checkAudio(mic):
    isAudio = False
    if(mic is not None):
        # record 1 second
        data = mic.record(samplerate=48000, numframes=48000)
        isAudio = np.any(data != 0)

    return (isAudio)

mic = getMic()
checkAudio(mic)
bastibe commented 4 years ago

Thank you for your bug report!

I have seen this issue before, but I was as of yet unable to figure out its cause. It seems that pulseaudio sometimes does not initialize a microphone, even though it works most other times with the very same settings. If you find any regularity in this problem, I would be grateful for the help!

It seems to only happen if many streams are opened in close succession, suggesting maybe a garbage collection or reference counting issue. Any ideas would be greatly appreciated!

rikvanriel commented 4 years ago

I suspect commit be44b6557d68147a5789f7174cf4880f2efe6901 will fix this issue.