Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Aug 24, 2024
1 parent e307b27 commit e687681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/opus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ impl StreamReader {
if sample_rate != 48000 && sample_rate != 24000 {
anyhow::bail!("sample-rate has to be 48000 or 24000, got {sample_rate}")
}
// TODO: look whether there is a more adapted channel type.
// TODO(laurent): look whether there is a more adapted channel type.
let (tx, rx) = tokio::io::duplex(100_000);
let decoder = opus::Decoder::new(sample_rate, opus::Channels::Mono)?;
let pr = ogg::reading::async_api::PacketReader::new(rx);
// TODO(laurent): consider spawning a thread so that the process happens in the background.
let runtime = tokio::runtime::Runtime::new()?;
let pcm_buf = vec![0f32; 24_000 * 10];
Ok(Self { pr, decoder, tx, runtime, pcm_buf })
Expand Down
13 changes: 11 additions & 2 deletions test/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
packet_size = 960
for lo in range(0, data.shape[-1], packet_size):
up = lo + packet_size
packet = data[:, lo:up]
packet = data[0, lo:up]
print(packet.shape)
stream_writer.append_pcm(packet[0])
if packet.shape[-1] != packet_size:
break
stream_writer.append_pcm(packet)

with open("myfile.opus", "wb") as fobj:
while True:
opus = stream_writer.read_bytes()
if len(opus) == 0:
break
fobj.write(opus)

0 comments on commit e687681

Please sign in to comment.