Works for transcribing audio, needs tunning
This commit is contained in:
parent
f463d0f68c
commit
36b6f8e70d
1 changed files with 24 additions and 29 deletions
|
@ -654,18 +654,20 @@ impl Transcriber {
|
||||||
|
|
||||||
gst_trace!(CAT, obj: element, "Sending {} bytes", data.len());
|
gst_trace!(CAT, obj: element, "Sending {} bytes", data.len());
|
||||||
|
|
||||||
ws_sink
|
for chunk in data.chunks(8_000) {
|
||||||
.send(Message::Binary(data.to_vec()))
|
ws_sink
|
||||||
.await
|
.send(Message::Binary(chunk.to_vec()))
|
||||||
.map_err(|err| {
|
.await
|
||||||
gst_error!(
|
.map_err(|err| {
|
||||||
CAT,
|
gst_error!(
|
||||||
obj: element,
|
CAT,
|
||||||
"Failed sending audio packet to server: {}",
|
obj: element,
|
||||||
err
|
"Failed sending audio packet to server: {}",
|
||||||
);
|
err
|
||||||
gst::FlowError::Error
|
);
|
||||||
})?;
|
gst::FlowError::Error
|
||||||
|
})?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
gst_info!(
|
gst_info!(
|
||||||
CAT,
|
CAT,
|
||||||
|
@ -767,16 +769,13 @@ impl Transcriber {
|
||||||
})?
|
})?
|
||||||
};
|
};
|
||||||
|
|
||||||
let (ws_sink, mut ws_stream) = ws.split();
|
let (mut ws_sink, mut ws_stream) = ws.split();
|
||||||
|
|
||||||
*self.ws_sink.borrow_mut() = Some(Box::pin(ws_sink));
|
|
||||||
|
|
||||||
let element_weak = element.downgrade();
|
let element_weak = element.downgrade();
|
||||||
let recv_handle = async move {
|
let recv_handle = async move {
|
||||||
// First, send configuration to the Vosk server
|
// First, send configuration to the Vosk server
|
||||||
if let Some(element) = element_weak.upgrade() {
|
if let Some(element) = element_weak.upgrade() {
|
||||||
let transcribe = element.imp();
|
let transcribe = element.imp();
|
||||||
let mut sender = transcribe.state.lock().unwrap().sender.clone();
|
|
||||||
|
|
||||||
// Set up the server to handle the incoming audio sample rate
|
// Set up the server to handle the incoming audio sample rate
|
||||||
let in_caps = transcribe.sinkpad.current_caps().unwrap();
|
let in_caps = transcribe.sinkpad.current_caps().unwrap();
|
||||||
|
@ -791,22 +790,18 @@ impl Transcriber {
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = Configuration::new(sample_rate);
|
let config = Configuration::new(sample_rate);
|
||||||
let packet = serde_json::to_vec(&config).unwrap();
|
let packet = serde_json::to_string(&config).unwrap();
|
||||||
let msg = Message::Binary(packet);
|
if ws_sink.send(Message::Text(packet)).await.is_err() {
|
||||||
|
gst_error!(
|
||||||
|
CAT,
|
||||||
|
obj: &element,
|
||||||
|
"Failed to configure Vosk server for the expected sample rate",
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(sender) = sender.as_mut() {
|
|
||||||
if sender.send(msg).await.is_err() {
|
|
||||||
gst_error!(
|
|
||||||
CAT,
|
|
||||||
obj: &element,
|
|
||||||
"Failed to configure Vosk server for the expected sample rate",
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*transcribe.ws_sink.borrow_mut() = Some(Box::pin(ws_sink));
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(element) = element_weak.upgrade() {
|
while let Some(element) = element_weak.upgrade() {
|
||||||
|
|
Loading…
Reference in a new issue