-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Live audio stream #2526
Comments
That's not something I have considered implementing. But you can pass an |
I had the same Idea but always get import pyaudio
import threading
import io
# Parameters
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 1024
class BufferedAudioStream(io.BufferedIOBase):
def __init__(self, format, channels, rate, chunk):
self.p = pyaudio.PyAudio()
self.stream = self.p.open(format=format,
channels=channels,
rate=rate,
input=True,
frames_per_buffer=chunk)
self.chunk = chunk
self.buffer = bytearray()
self.lock = threading.Lock()
self.running = True
def read(self, size=-1):
with self.lock:
if size == -1:
size = len(self.buffer)
data = self.buffer[:size]
self.buffer = self.buffer[size:]
return bytes(data)
def update_buffer(self):
while self.running:
data = self.stream.read(self.chunk)
with self.lock:
self.buffer.extend(data)
def close(self):
self.running = False
self.stream.stop_stream()
self.stream.close()
self.p.terminate()
# Initialize BufferedAudioStream
audio_stream = BufferedAudioStream(FORMAT, CHANNELS, RATE, CHUNK)
# Start the buffer update thread
buffer_thread = threading.Thread(target=audio_stream.update_buffer)
buffer_thread.start()
await atv.stream.stream_file(audio_stream) |
i have also tried using |
Metadata detection is failing (for some reason). Try passing some bogus metadata to see if that helps (it will disable auto detection). |
Unfortunately this didn't work for me |
Can you provide a more detailed exception of what is happening? |
Yes. When I use the code above, I get the following error: This is probably because the stream doesn't have any header information to indicate what format it is. Then I tried using it as a stream reader, but I got the same error. With the library |
Do you have an idea how to implement this? Or have an idea what the problem is? |
I believe you are on to the problem already. pyatv expects a proper container format (e.g. mp3 or ogg) and cannot decode raw PCM frames at the moment. That could probably be implemented in some intricate way, but I can't say how I would do it right now. I will have to think about it a bit. |
What do you need help with?
Is there or will there be a possibility to just feed an pyaudio stream to
stream.stream_file
?This is to get the stream:
The text was updated successfully, but these errors were encountered: