Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sd.Stream sounds not smooth #472

Open
yufengyao-lingoace opened this issue Jun 14, 2023 · 1 comment
Open

sd.Stream sounds not smooth #472

yufengyao-lingoace opened this issue Jun 14, 2023 · 1 comment

Comments

@yufengyao-lingoace
Copy link

yufengyao-lingoace commented Jun 14, 2023

When I use this code, the audio sounds not smooth. I am trying recording and playing at the same time, but I found it worded bad on mac, but normal on windows. I got a noisy sound on mac, when the recording is open. But it sounds normal when I stopped the recording process.

def stream_generator(blocksize, *, channels=1, dtype='float32',pre_fill_blocks=10):

    data, fs = sf.read("tmp.wav", always_2d=True)
    
    def callback(indata, outdata, frame_count, time_info, status):
        global current_frame
        chunksize = min(len(data) - current_frame, frame_count)
        outdata[:chunksize] = data[current_frame:current_frame + chunksize]
        if chunksize < frame_count:
            outdata[chunksize:] = 0
            raise sd.CallbackStop()
        current_frame += chunksize


    stream = sd.Stream(samplerate=22050,blocksize=4096, device=[0,1], callback=callback, dtype=dtype,
                       channels=1)
    with stream:
        event.wait()

stream_generator(1024)
@mgeier
Copy link
Member

mgeier commented Feb 2, 2024

The event variable is not defined, or am I missing something?

Do the example programs work on mac/windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants