Replies: 2 comments 1 reply
-
Hi Michel, I'm still not entirely clear on your specific application. However it sounds a lot like an audio-conferencing application. With audio conferencing you would send Opus-encoded audio between, say, two participants. The sender records audio, which is broken into "chunks" as required by the Opus specification. The chucks' duration must be one of 2.5, 5, 10, 20, 40, or 60 ms. The sender then sends the Opus-encoded audio to the sender via an established network connection (typically UDP over IP). The receiver receives the Opus-encoded "chunk" and decodes it into PCM, which it then plays back. The receiver cannot entirely rely on the "chunks" arriving at the correct time (due, for example, to network delays) so a small jitter buffer is often implemented by the receiver. Note that this technique does not require Ogg encapsulation as the UDP framing may fill that role. If you are interested in implementing such a system, then the class If however you already have Opus-encoded audio from another application, and it is responsible for streaming the audio, then you would only need to write a "receiver". In this case I would recommend that you consider the class To answer your two specific questions:
I hope that helps, Matthew |
Beta Was this translation helpful? Give feedback.
-
Thanks Matthew, My application is only the "sender" in your response above.
You have shared how to get duration:
Having a pcm chunk (as numpy array) in "buf", how can I make "buf" back into a opus "chunk"? You suggest the use of "OpusBufferedEncoder". I have played with it
return: pcm_ctypes = Buffer.from_buffer(pcm_bytes) TypeError: underlying buffer is not writable "buf" type is probaby not correctly handle in my example. If you could help I would aprreciate. Thanks Michel |
Beta Was this translation helpful? Give feedback.
-
As you suggested I am bringing one discussion into a distinct one.
My current knowledge of opus/ogg is limited at this moment. Some of my wording could be misleading because non-applicable.
The application:
Thanks Matthew for your suggestion.
Suggestion:
I would recommend that you consider OpusFileStream.
OpusFileStream.get_buffer() or OpusFileStream.get_buffer_as_array() will get you the next "chunk" of PCM (decoded audio).
The duration of that PCM can be easily calculated. First find the length of the chuck in samples, then divide it by 48,000 (which is the number of samples per second for Opus-encoded audio). That gives you the length in seconds. Something like the following:
array = stream.get_buffer_as_array()
length_samples = len(array)
samples_per_second = stream.frequency
length_seconds = length_samples / samples_per_second
Question:
Thanks
Michel
Beta Was this translation helpful? Give feedback.
All reactions