Initial commit

This commit is contained in:
Rafael Caricio 2022-03-27 11:31:47 +02:00
commit 33b7959fab
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
9 changed files with 2333 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1143
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

47
Cargo.toml Normal file
View file

@ -0,0 +1,47 @@
[package]
name = "gst-plugin-vosk"
version = "0.1.0"
edition = "2021"
authors = ["Rafael Caricio <rafael@caricio.com>"]
repository = ""
license = "MPL-2.0"
description = "plugin"
build = "build.rs"
[dependencies]
gst = { package = "gstreamer", version = "0.18" }
gstreamer-base = "0.18"
once_cell = "1"
atomic_refcell = "0.1"
serde = "1"
serde_derive = "1"
serde_json = "1"
futures = "0.3"
tokio = { version = "1.0", features = [ "rt-multi-thread", "time" ] }
async-tungstenite = { version = "0.17", features = ["tokio", "tokio-runtime", "tokio-native-tls"] }
[build-dependencies]
gst-plugin-version-helper = "0.7.3"
[lib]
name = "gstvosk"
crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"
[features]
# GStreamer 1.14 is required for static linking
static = ["gst/v1_14"]
capi = []
[package.metadata.capi]
min_version = "0.8.0"
[package.metadata.capi.header]
enabled = false
[package.metadata.capi.library]
install_subdir = "gstreamer-1.0"
versioning = false
[package.metadata.capi.pkg_config]
requires_private = "gstreamer-1.0, gstreamer-base-1.0, gobject-2.0, glib-2.0, gmodule-2.0"

5
README.md Normal file
View file

@ -0,0 +1,5 @@
Vosk Speech Recognition GStreamer Plugin
========================================
Transcription of speech using [Vosk Toolkit](https://alphacephei.com/vosk/). Can be used to generate subtitles for
videos, transcription of audio notes, etc.

3
build.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
gst_plugin_version_helper::info()
}

29
src/lib.rs Normal file
View file

@ -0,0 +1,29 @@
// Copyright (C) 2022 Rafael Caricio <rafael@caricio.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// <https://mozilla.org/MPL/2.0/>.
//
// SPDX-License-Identifier: MPL-2.0
use gst::glib;
mod transcriber;
mod vosk_client;
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
transcriber::register(plugin)?;
Ok(())
}
gst::plugin_define!(
vosktranscriber,
env!("CARGO_PKG_DESCRIPTION"),
plugin_init,
concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")),
"MPL",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_REPOSITORY"),
env!("BUILD_REL_DATE")
);

1042
src/transcriber/imp.rs Normal file

File diff suppressed because it is too large Load diff

28
src/transcriber/mod.rs Normal file
View file

@ -0,0 +1,28 @@
// Copyright (C) 2022 Rafael Caricio <rafael@caricio.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// <https://mozilla.org/MPL/2.0/>.
//
// SPDX-License-Identifier: MPL-2.0
use glib::prelude::*;
use gst::glib;
mod imp;
glib::wrapper! {
pub struct Transcriber(ObjectSubclass<imp::Transcriber>) @extends gst::Element, gst::Object;
}
unsafe impl Send for Transcriber {}
unsafe impl Sync for Transcriber {}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(
Some(plugin),
"vosk_transcriber",
gst::Rank::None,
Transcriber::static_type(),
)
}

35
src/vosk_client/mod.rs Normal file
View file

@ -0,0 +1,35 @@
use serde_derive::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct Configuration {
/// Sample rate the audio will be provided at.
sample_rate: i32,
/// Show time ranges of each word in the transcription.
words: bool,
}
impl Configuration {
pub fn new(sample_rate: i32) -> Self {
Self {
sample_rate,
// We always want to receive the words with their time ranges.
words: true,
}
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Transcript {
pub result: Vec<WordInfo>,
pub text: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct WordInfo {
#[serde(rename = "conf")]
pub confidence: f64,
pub word: String,
pub start: f64,
pub end: f64,
}