PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.39k stars 291 forks source link

Errors using pyaudio #871

Closed marcomac01 closed 6 months ago

marcomac01 commented 6 months ago

hello there. i get a bunch of errors using pyaudio to play pcms. there's a sort of stuttering. The code follows: import pymumble_py3 as pymumble

from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
from pymumble_py3.callbacks import PYMUMBLE_CLBK_CONNECTED as PCCONNECTED
from pymumble_py3.callbacks import PYMUMBLE_CLBK_DISCONNECTED as PCDISCONNECTED

import pyaudio
import time

pwd = ""  # password
server = "192.168.1.61"  # server address
nick = "pi"
port = 64738  # port number

# pyaudio set up
CHUNK = 1024
FORMAT = pyaudio.paInt16  # pymumble soundchunk.pcm is 16 bits
CHANNELS = 1
RATE = 48000  # pymumble soundchunk.pcm is 48000Hz

p = pyaudio.PyAudio()

input_stream = p.open(format=FORMAT,

                channels=CHANNELS,
                rate=RATE,
                input=True,  # enable both talk
        frames_per_buffer=CHUNK)

output_stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                output=True,  # and listen
                frames_per_buffer=CHUNK,
                output_device_index = RESPEAKER_INDEX)

# mumble client set up
def sound_received_handler(user, soundchunk):
    """ play sound received from mumble server upon its arrival """
    output_stream.write(soundchunk.pcm)

mumble = pymumble.Mumble(server, nick, password=pwd, port=port, reconnect=True)
mumble.callbacks.set_callback(PCS, sound_received_handler)

mumble.set_receive_sound(1)  # Enable receiving sound from mumble server
mumble.start()
mumble.is_ready()  # Wait for client is ready

try:
    while True:
        #data = input_stream.read(CHUNK, exception_on_overflow=False)
        #mumble.sound_output.add_sound(data)
        pass

except KeyboardInterrupt:
    print("\nCtrl+C detected. Exiting...")
    print("Cleaning up resources.")
    # close the stream and pyaudio instance
    input_stream.stop_stream()
    input_stream.close()
    p.terminate()

thanks for your patience

RossBencina commented 6 months ago

This is the repository for the PortAudio C library. Unless you can provide C code that reproduces your issue we're unable to help you here. I recommend that you seek support from the pyaudio project.

Stuttering is often the symptom of missing deadlines (i.e. your processing is taking too long) but that's just a guess.

philburk commented 6 months ago

It looks like you might be using a server or worker thread with a callback. You might have better luck just getting the data from the server and then doing a blocking write.