Skip to content

Commit

Permalink
test(sound): check sound files in rust tests (#282)
Browse files Browse the repository at this point in the history
- instead of invoking soxi with bash script.
- check that all files are present in the assets
- check bits per sample (16 bits)
- sounds directory based on cargo manifest path for tests
  • Loading branch information
fouge authored Nov 14, 2024
1 parent e77dc22 commit e4c8de1
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 176 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/check-sound-files.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/rust-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # pin@v3
with:
token: ${{ secrets.GIT_HUB_TOKEN }}
lfs: true
- uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # pin@v27
with:
github_access_token: ${{ secrets.GIT_HUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ path = "examples/ui-replay.rs"
# dependencies for the dbus-client example
[dev-dependencies]
chrono = "0.4.35"
hound = "3.5.1"

[package.metadata.deb]
maintainer-scripts = "debian/"
Expand Down
17 changes: 5 additions & 12 deletions ui/sound/examples/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ impl AsRef<[u8]> for Sound {
async fn main() -> Result<()> {
let queue = Queue::spawn("default")?;

let connected = Sound(Arc::new(fs::read("sound/examples/voice_connected.wav")?));
let overheating =
Sound(Arc::new(fs::read("sound/examples/voice_overheating.wav")?));
let connected = Sound(Arc::new(fs::read("sound/assets/voice_connected.wav")?));
let timeout = Sound(Arc::new(fs::read("sound/assets/voice_timeout.wav")?));

// Said firstly because the queue starts playing immediately.
queue
Expand All @@ -40,19 +39,13 @@ async fn main() -> Result<()> {
// Said secondly because it has a higher priority than all pending sounds in
// the queue.
queue
.sound(
Some(Cursor::new(overheating.clone())),
"overheating".to_string(),
)
.sound(Some(Cursor::new(timeout.clone())), "timeout".to_string())
.priority(1)
.push()?;
// Not said because it doesn't meet the `max_delay`.
assert!(
!queue
.sound(
Some(Cursor::new(overheating.clone())),
"overheating".to_string()
)
.sound(Some(Cursor::new(timeout.clone())), "timeout".to_string())
.priority(1)
.max_delay(Duration::from_secs(1))
.push()?
Expand All @@ -72,7 +65,7 @@ async fn main() -> Result<()> {
);

// In result the queue should be played in the following order: connected,
// overheating, connected, connected.
// timeout, connected, connected.

Ok(())
}
3 changes: 0 additions & 3 deletions ui/sound/examples/voice_connected.wav

This file was deleted.

3 changes: 0 additions & 3 deletions ui/sound/examples/voice_overheating.wav

This file was deleted.

2 changes: 1 addition & 1 deletion ui/sound/examples/wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() -> Result<()> {
let mut device = Device::open("default")?;
let mut hw_params = HwParams::new()?;

let mut wav = File::open("sound/examples/voice_connected.wav")?;
let mut wav = File::open("sound/assets/voice_connected.wav")?;
device.play_wav(&mut wav, &mut hw_params, 1.0)?;
device.drain()?;

Expand Down
9 changes: 0 additions & 9 deletions ui/sound/utils/README.md

This file was deleted.

52 changes: 0 additions & 52 deletions ui/sound/utils/check_sounds.sh

This file was deleted.

19 changes: 12 additions & 7 deletions ui/src/engine/diamond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ pub async fn event_loop(
Runner::<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT>::new(sound)
}
Err(e) => {
return {
tracing::error!("Failed to initialize sound: {:?}", e);
Err(e)
};
return Err(eyre::eyre!("Failed to initialize sound: {:?}", e));
}
};
loop {
Expand Down Expand Up @@ -935,9 +932,17 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
let sound = self.sound.clone();
// spawn a new task because we need some async work here
tokio::task::spawn(async move {
let language: Option<&str> = language.as_deref();
if let Err(e) = sound.load_sound_files(language, true).await {
tracing::error!("Error loading sound files: {:?}", e);
match sound::SoundConfig::default()
.with_language(language.as_deref())
{
Ok(config) => {
if let Err(e) = sound.load_sound_files(config).await {
tracing::error!("Error loading sound files: {:?}", e);
}
}
Err(e) => {
tracing::error!("Error creating sound config: {:?}", e);
}
}
});
}
Expand Down
21 changes: 14 additions & 7 deletions ui/src/engine/pearl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ pub async fn event_loop(
interval.set_missed_tick_behavior(time::MissedTickBehavior::Delay);
let mut interval = IntervalStream::new(interval);
let mut rx = UnboundedReceiverStream::new(rx);
let mut runner = if let Ok(sound) = sound::Jetson::spawn().await {
Runner::<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT>::new(sound)
} else {
return Err(eyre::eyre!("Failed to initialize sound"));
let mut runner = match sound::Jetson::spawn().await {
Ok(sound) => Runner::<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT>::new(sound),
Err(e) => return Err(eyre::eyre!("Failed to initialize sound: {:?}", e)),
};
loop {
match future::select(rx.next(), interval.next()).await {
Expand Down Expand Up @@ -274,9 +273,17 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
let sound = self.sound.clone();
// spawn a new task because we need some async work here
tokio::task::spawn(async move {
let language: Option<&str> = language.as_deref();
if let Err(e) = sound.load_sound_files(language, true).await {
tracing::error!("Error loading sound files: {:?}", e);
match sound::SoundConfig::default()
.with_language(language.as_deref())
{
Ok(config) => {
if let Err(e) = sound.load_sound_files(config).await {
tracing::error!("Error loading sound files: {:?}", e);
}
}
Err(e) => {
tracing::error!("Error creating sound config: {:?}", e);
}
}
});
}
Expand Down
Loading

0 comments on commit e4c8de1

Please sign in to comment.