aboutsummaryrefslogtreecommitdiffstats
path: root/crates/asist-audio/src/capture.rs
diff options
context:
space:
mode:
authorelvis <elvis@claros.ar>2026-09-26 20:20:19 -0300
committerelvis <elvis@claros.ar>2026-09-26 20:20:19 -0300
commit8518a63f55153e7f45fd49ad6caff5555f4e374f (patch)
tree636684eea3fa6f35d78282ab95eb687ef49154af /crates/asist-audio/src/capture.rs
parent69de76dc9cbedc6092d1e5ce84094a8030de1470 (diff)
downloadasist-p-main.tar.gz
asist-p-main.zip
Translate code, comments, logs and terminal UI to English; add English README; rename scriptsHEADmain
Diffstat (limited to 'crates/asist-audio/src/capture.rs')
-rw-r--r--crates/asist-audio/src/capture.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/crates/asist-audio/src/capture.rs b/crates/asist-audio/src/capture.rs
index 05da992..5e3a697 100644
--- a/crates/asist-audio/src/capture.rs
+++ b/crates/asist-audio/src/capture.rs
@@ -1,4 +1,4 @@
-//! Captura desde el micrófono.
+//! Microphone capture.
use std::time::Instant;
@@ -11,15 +11,15 @@ use asist_core::error::{Error, Result};
use crate::{describe, ASR_SAMPLE_RATE};
-/// Formato con el que se abrió realmente el dispositivo.
+/// Format the device was actually opened with.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InputFormat {
pub sample_rate: usize,
pub channels: usize,
}
-/// Un bloque tal y como sale de la retrollamada, con la marca de tiempo que
-/// permite luego medir cuánto se ha retrasado el pipeline respecto de la voz.
+/// A block as it comes out of the callback, with the timestamp that later
+/// lets us measure how far the pipeline lags behind the voice.
#[derive(Debug)]
pub struct CaptureBlock {
pub samples: Vec<f32>,
@@ -33,10 +33,10 @@ pub struct Capture {
}
impl Capture {
- /// Abre la entrada y empieza a empujar bloques por `tx`.
+ /// Opens the input and starts pushing blocks through `tx`.
///
- /// Prefiere 16 kHz mono porque es justo lo que quiere el modelo: si el
- /// dispositivo lo acepta, no hay remuestreo en ningún punto del camino.
+ /// It prefers 16 kHz mono because that is exactly what the model wants: if
+ /// the device accepts it, there is no resampling anywhere on the path.
pub fn open(config: &AudioConfig, tx: Sender<CaptureBlock>) -> Result<Self> {
let host = cpal::default_host();
let device = select_device(&host, &config.input_device)?;
@@ -48,11 +48,11 @@ impl Capture {
channels: supported.channels() as usize,
};
let stream_config: cpal::StreamConfig = supported.clone().into();
- let on_error = |err| tracing::error!(target: "audio", %err, "flujo de entrada");
+ let on_error = |err| tracing::error!(target: "audio", %err, "input stream");
- // Dentro de la retrollamada: convertir a f32, enviar y salir. `send`
- // sobre un canal sin límite no bloquea, que es la única propiedad que
- // aquí importa.
+ // Inside the callback: convert to f32, send and leave. `send` on an
+ // unbounded channel does not block, which is the only property that
+ // matters here.
macro_rules! build {
($sample:ty) => {
device
@@ -68,7 +68,7 @@ impl Capture {
on_error,
None,
)
- .map_err(|e| Error::Audio(format!("no se pudo abrir la entrada: {e}")))?
+ .map_err(|e| Error::Audio(format!("could not open the input: {e}")))?
};
}
@@ -78,20 +78,20 @@ impl Capture {
SampleFormat::U16 => build!(u16),
other => {
return Err(Error::Audio(format!(
- "formato de muestra no soportado: {other:?}"
+ "unsupported sample format: {other:?}"
)))
}
};
stream
.play()
- .map_err(|e| Error::Audio(format!("no se pudo arrancar la entrada: {e}")))?;
+ .map_err(|e| Error::Audio(format!("could not start the input: {e}")))?;
tracing::info!(
target: "audio",
- dispositivo = %device_name,
+ device = %device_name,
hz = format.sample_rate,
- canales = format.channels,
- remuestreo = format.sample_rate != ASR_SAMPLE_RATE as usize || format.channels != 1,
+ channels = format.channels,
+ resampling = format.sample_rate != ASR_SAMPLE_RATE as usize || format.channels != 1,
"entrada abierta"
);
@@ -102,8 +102,8 @@ impl Capture {
})
}
- /// Cierra el dispositivo. Al soltar el emisor, la cadena de hilos se
- /// desmonta sola de arriba abajo.
+ /// Closes the device. Dropping the sender makes the chain of threads
+ /// take itself apart from top to bottom.
pub fn stop(self) {
drop(self.stream);
}
@@ -113,12 +113,12 @@ fn select_device(host: &cpal::Host, wanted: &str) -> Result<cpal::Device> {
if wanted.is_empty() {
return host
.default_input_device()
- .ok_or_else(|| Error::Audio("no hay dispositivo de entrada".into()));
+ .ok_or_else(|| Error::Audio("no input device".into()));
}
let wanted_lower = wanted.to_lowercase();
let devices = host
.input_devices()
- .map_err(|e| Error::Audio(format!("no se pudieron listar las entradas: {e}")))?;
+ .map_err(|e| Error::Audio(format!("could not list the inputs: {e}")))?;
let mut seen = Vec::new();
for device in devices {
let name = describe(&device);
@@ -128,7 +128,7 @@ fn select_device(host: &cpal::Host, wanted: &str) -> Result<cpal::Device> {
seen.push(name);
}
Err(Error::Audio(format!(
- "ninguna entrada coincide con «{wanted}». Disponibles: {}",
+ "no input matches «{wanted}». Available: {}",
seen.join(", ")
)))
}
@@ -136,7 +136,7 @@ fn select_device(host: &cpal::Host, wanted: &str) -> Result<cpal::Device> {
fn preferred_config(device: &cpal::Device) -> Result<SupportedStreamConfig> {
let native = device
.supported_input_configs()
- .map_err(|e| Error::Audio(format!("no se pudo consultar la entrada: {e}")))?
+ .map_err(|e| Error::Audio(format!("could not query the input: {e}")))?
.filter(|range| range.channels() == 1)
.filter(|range| {
range.min_sample_rate() <= ASR_SAMPLE_RATE && ASR_SAMPLE_RATE <= range.max_sample_rate()
@@ -148,6 +148,6 @@ fn preferred_config(device: &cpal::Device) -> Result<SupportedStreamConfig> {
Some(config) => Ok(config),
None => device
.default_input_config()
- .map_err(|e| Error::Audio(format!("sin configuración de entrada: {e}"))),
+ .map_err(|e| Error::Audio(format!("no input configuration: {e}"))),
}
}