Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ hypr-askama-utils = { path = "crates/askama-utils", package = "askama-utils" }
hypr-audio = { path = "crates/audio", package = "audio" }
hypr-audio-device = { path = "crates/audio-device", package = "audio-device" }
hypr-audio-interface = { path = "crates/audio-interface", package = "audio-interface" }
hypr-audio-mime = { path = "crates/audio-mime", package = "audio-mime" }
hypr-audio-utils = { path = "crates/audio-utils", package = "audio-utils" }
hypr-buffer = { path = "crates/buffer", package = "buffer" }
hypr-bundle = { path = "crates/bundle", package = "bundle" }
Expand Down
6 changes: 6 additions & 0 deletions crates/audio-mime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "audio-mime"
version = "0.1.0"
edition = "2024"

[dependencies]
42 changes: 42 additions & 0 deletions crates/audio-mime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pub fn content_type_to_extension(content_type: &str) -> &'static str {
let mime = content_type
.split(';')
.next()
.unwrap_or(content_type)
.trim();
match mime {
"audio/wav" | "audio/wave" | "audio/x-wav" => "wav",
"audio/mpeg" | "audio/mp3" => "mp3",
"audio/ogg" => "ogg",
"audio/flac" => "flac",
"audio/mp4" | "audio/m4a" | "audio/x-m4a" => "m4a",
"audio/webm" => "webm",
"audio/aac" => "aac",
_ => "wav",
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn content_type_mapping() {
assert_eq!(content_type_to_extension("audio/wav"), "wav");
assert_eq!(content_type_to_extension("audio/wave"), "wav");
assert_eq!(content_type_to_extension("audio/mpeg"), "mp3");
assert_eq!(content_type_to_extension("audio/mp3"), "mp3");
assert_eq!(content_type_to_extension("audio/ogg"), "ogg");
assert_eq!(content_type_to_extension("audio/flac"), "flac");
assert_eq!(content_type_to_extension("audio/m4a"), "m4a");
assert_eq!(content_type_to_extension("audio/webm"), "webm");
assert_eq!(content_type_to_extension("audio/aac"), "aac");
assert_eq!(content_type_to_extension("application/octet-stream"), "wav");
}

#[test]
fn content_type_with_charset() {
assert_eq!(content_type_to_extension("audio/wav; charset=utf-8"), "wav");
assert_eq!(content_type_to_extension("audio/mpeg; bitrate=128"), "mp3");
}
}
1 change: 1 addition & 0 deletions crates/audio-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2024"
bytes = { workspace = true }
futures-util = { workspace = true }
hypr-audio-interface = { workspace = true }
hypr-audio-mime = { workspace = true }
pin-project = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/audio-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ pub fn mix_audio_pcm16le(mic: &[u8], speaker: &[u8]) -> Vec<u8> {
mixed
}

pub use hypr_audio_mime::content_type_to_extension;

pub fn source_from_path(
path: impl AsRef<std::path::Path>,
) -> Result<rodio::Decoder<std::io::BufReader<std::fs::File>>, crate::Error> {
Expand Down
43 changes: 1 addition & 42 deletions crates/transcribe-cactus/src/service/batch/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,4 @@ pub(super) fn audio_duration_secs(path: &Path) -> f64 {
count / channels / sample_rate
}

pub(super) fn content_type_to_extension(content_type: &str) -> &'static str {
let mime = content_type
.split(';')
.next()
.unwrap_or(content_type)
.trim();
match mime {
"audio/wav" | "audio/wave" | "audio/x-wav" => "wav",
"audio/mpeg" | "audio/mp3" => "mp3",
"audio/ogg" => "ogg",
"audio/flac" => "flac",
"audio/mp4" | "audio/m4a" | "audio/x-m4a" => "m4a",
"audio/webm" => "webm",
"audio/aac" => "aac",
_ => "wav",
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn content_type_mapping() {
assert_eq!(content_type_to_extension("audio/wav"), "wav");
assert_eq!(content_type_to_extension("audio/wave"), "wav");
assert_eq!(content_type_to_extension("audio/mpeg"), "mp3");
assert_eq!(content_type_to_extension("audio/mp3"), "mp3");
assert_eq!(content_type_to_extension("audio/ogg"), "ogg");
assert_eq!(content_type_to_extension("audio/flac"), "flac");
assert_eq!(content_type_to_extension("audio/m4a"), "m4a");
assert_eq!(content_type_to_extension("audio/webm"), "webm");
assert_eq!(content_type_to_extension("audio/aac"), "aac");
assert_eq!(content_type_to_extension("application/octet-stream"), "wav");
}

#[test]
fn content_type_with_charset() {
assert_eq!(content_type_to_extension("audio/wav; charset=utf-8"), "wav");
assert_eq!(content_type_to_extension("audio/mpeg; bitrate=128"), "mp3");
}
}
pub(super) use hypr_audio_utils::content_type_to_extension;
1 change: 1 addition & 0 deletions crates/transcribe-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2024"
hypr-analytics = { workspace = true }
hypr-api-auth = { workspace = true }
hypr-api-env = { workspace = true }
hypr-audio-mime = { workspace = true }
hypr-language = { workspace = true }
hypr-supabase-storage = { workspace = true }
owhisper-client = { workspace = true }
Expand Down
21 changes: 2 additions & 19 deletions crates/transcribe-proxy/src/routes/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use axum::{
use hypr_api_auth::AuthContext;
use owhisper_interface::ListenParams;

use hypr_audio_mime::content_type_to_extension;

use crate::hyprnote_routing::should_use_hyprnote_routing;
use crate::query_params::QueryParams;

Expand Down Expand Up @@ -113,22 +115,3 @@ fn write_to_temp_file(

Ok(temp_file)
}

fn content_type_to_extension(content_type: &str) -> &'static str {
let mime = content_type
.split(';')
.next()
.unwrap_or(content_type)
.trim();

match mime {
"audio/wav" | "audio/wave" | "audio/x-wav" => "wav",
"audio/mpeg" | "audio/mp3" => "mp3",
"audio/ogg" => "ogg",
"audio/flac" => "flac",
"audio/mp4" | "audio/m4a" | "audio/x-m4a" => "m4a",
"audio/webm" => "webm",
"audio/aac" => "aac",
_ => "wav",
}
}
Loading