From 981426b681161f019fc65646250352857a49aad4 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sun, 6 Sep 2020 00:02:19 +0200 Subject: [PATCH] Expose PCM data in Rust --- Cargo.toml | 1 + src/agents/audio_agent.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1d2bbf4..02a5d5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,4 +22,5 @@ version = "0.3.44" features = [ "console", "AudioContext", + "AudioBuffer", ] diff --git a/src/agents/audio_agent.rs b/src/agents/audio_agent.rs index a12faba..5f619ab 100644 --- a/src/agents/audio_agent.rs +++ b/src/agents/audio_agent.rs @@ -64,7 +64,10 @@ impl Agent for AudioAgent { } } Msg::AudioDecoded(samples) => { - ConsoleService::log(&format!("Success decoding: {:?}", samples)); + let audio_buffer = web_sys::AudioBuffer::from(samples); + let data = audio_buffer.get_channel_data(0).unwrap(); // TODO: error handling + let vec: Vec = data.to_vec(); + ConsoleService::log(&format!("Success decoding: {:?}", vec)); } Msg::AudioDecodingFailed(err) => { ConsoleService::error(&format!("Error decoding: {:?}", err));