Works for transcribing audio, needs tunning

This commit is contained in:
Rafael Caricio 2022-03-31 15:40:08 +02:00
parent f463d0f68c
commit 36b6f8e70d
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947

View file

@ -654,8 +654,9 @@ impl Transcriber {
gst_trace!(CAT, obj: element, "Sending {} bytes", data.len());
for chunk in data.chunks(8_000) {
ws_sink
.send(Message::Binary(data.to_vec()))
.send(Message::Binary(chunk.to_vec()))
.await
.map_err(|err| {
gst_error!(
@ -666,6 +667,7 @@ impl Transcriber {
);
gst::FlowError::Error
})?;
}
} else {
gst_info!(
CAT,
@ -767,16 +769,13 @@ impl Transcriber {
})?
};
let (ws_sink, mut ws_stream) = ws.split();
*self.ws_sink.borrow_mut() = Some(Box::pin(ws_sink));
let (mut ws_sink, mut ws_stream) = ws.split();
let element_weak = element.downgrade();
let recv_handle = async move {
// First, send configuration to the Vosk server
if let Some(element) = element_weak.upgrade() {
let transcribe = element.imp();
let mut sender = transcribe.state.lock().unwrap().sender.clone();
// Set up the server to handle the incoming audio sample rate
let in_caps = transcribe.sinkpad.current_caps().unwrap();
@ -791,11 +790,8 @@ impl Transcriber {
);
let config = Configuration::new(sample_rate);
let packet = serde_json::to_vec(&config).unwrap();
let msg = Message::Binary(packet);
if let Some(sender) = sender.as_mut() {
if sender.send(msg).await.is_err() {
let packet = serde_json::to_string(&config).unwrap();
if ws_sink.send(Message::Text(packet)).await.is_err() {
gst_error!(
CAT,
obj: &element,
@ -804,9 +800,8 @@ impl Transcriber {
return;
}
} else {
return;
}
*transcribe.ws_sink.borrow_mut() = Some(Box::pin(ws_sink));
}
while let Some(element) = element_weak.upgrade() {