Skip to content

Commit

Permalink
Refactor/UI (#66)
Browse files Browse the repository at this point in the history
* fix warnings

* imporove desktop imports

* improve landing imports

* update desktop packages

* update landing packages

* setup eslint on desktop

* improve pre build

* feat: allow import svgs

* refactor: move svg to icons folder

* simplify naming

* format all files

* update funding

* fix eslint warnings

* organize imports

* organize imports

* simplify cli

* spelling

* add extensions recommendation

* add i18n ally

* fix translations

* remove unused file

* refactor

* refactor

* feat: namespace translation

* improve localization, add namespaces

* fix translation

* fix translation

* copy locales to out dir

* add chainese

* add fs extra

* refactor

* improve translation

* organize config

* refactor

* refactor

* revert tauri version

* update readme

* simplify tauri config

* move locales to desktop folder

* rename wav files

* refactor

* refactor

* format landing files

* refactor
  • Loading branch information
thewh1teagle authored May 18, 2024
1 parent 13f5a67 commit f49021c
Show file tree
Hide file tree
Showing 123 changed files with 2,837 additions and 7,036 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"printWidth": 160,
"tabWidth": 4,
"useTabs": false,
"useTabs": true,
"bracketSameLine": true,
"endOfLine": "lf",
"singleQuote": true,
Expand Down
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"tauri-apps.tauri-vscode", // Tauri is a framework for building lightweight, secure applications with web technologies
"rust-lang.rust-analyzer", // Provides Rust language support
"editorconfig.editorconfig", // EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs
"bradlc.vscode-tailwindcss", // Provides Tailwind CSS IntelliSense
"dbaeumer.vscode-eslint", // Integrates ESLint JavaScript into VS Code
"esbenp.prettier-vscode", // Code formatter using prettier,
"lokalise.i18n-ally" // i18n-ally is an all-in-one i18n (internationalization) extension for VS Code
]
}
29 changes: 22 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
{
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
// General
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always",
},
"files.eol": "\n",

// Rust analyzer
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
// "source.organizeImports": "explicit",
// "source.fixAll": "explicit"
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},

// Formatting
"prettier.configPath": ".prettierrc.json",
"files.eol": "\n"

// i18n
"i18n-ally.enabledParsers": ["ts", "json"],
"i18n-ally.sortKeys": true,
"i18n-ally.namespace": true,
"i18n-ally.sourceLanguage": "en",
"i18n-ally.enabledFrameworks": ["react", "svelte"],
"i18n-ally.keystyle": "flat",
"i18n-ally.translate.engines": ["google",],
"i18n-ally.localesPaths": ["desktop/src-tauri/locales"],
"i18n-ally.pathMatcher": "{locale}/{namespace}.json",
}
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Currenly, listening for the audio file isn't supported on `Linux`

Offline installation with Vibe is easy: open the app, cancel the download, and navigate to the `Customize` section within settings.


# Contribute 🤝

PRs are welcomed!
Expand All @@ -89,10 +88,11 @@ You can see the roadmap in [Vibe-Roadmap](https://github.com/users/thewh1teagle/

# Add translation 🌐

1. Copy `en.json` from `locales` folder
2. Create new file eg `ru.json` (use [bcp47 language code](https://gist.github.com/thewh1teagle/c8877e5c4c5e2780754ddd065ae2592e))
3. Change every value to the new language and keep the keys as is
4. create PR / issue in Github
1. Copy `en` from `desktop/locales` folder to new directory eg `pt-BR` (use [bcp47 language code](https://gist.github.com/thewh1teagle/c8877e5c4c5e2780754ddd065ae2592e))
2. Change every value in the files there, to the new language and keep the keys as is
3. create PR / issue in Github

In addition you can add translation to [Vibe website](https://thewh1teagle.github.io/vibe/) by creating new files in the `landing/locales`.

# Build 🛠️

Expand Down
18 changes: 9 additions & 9 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::{fmt::Write, path::PathBuf, sync::Mutex};
use vibe::{self, model::SegmentCallbackData, transcript::Segment};

static PROGRESS_INSTANCE: once_cell::sync::Lazy<Mutex<Option<ProgressBar>>> = once_cell::sync::Lazy::new(|| Mutex::new(None));
static PROGRESS_INSTANCE_ASYNC: once_cell::sync::Lazy<tokio::sync::Mutex<Option<ProgressBar>>> =
once_cell::sync::Lazy::new(|| tokio::sync::Mutex::new(None));

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -20,8 +18,9 @@ pub struct Args {
pub model: Option<String>,

/// Language spoken in the audio. Attempts to auto-detect by default.
#[clap(short, long)]
pub lang: Option<vibe::language::Language>,
/// TODO: add possible values derived from whisper-languages.json
#[clap(short, long, default_value = "en")]
pub lang: String,

/// Verbose output
#[arg(long, action=ArgAction::SetTrue, default_value_t = false)]
Expand All @@ -32,10 +31,11 @@ pub struct Args {
pub n_threads: Option<i32>,
}

async fn on_download_progress(current: u64, total: u64) {
if let Some(pb) = PROGRESS_INSTANCE_ASYNC.lock().await.as_ref() {
fn on_download_progress(current: u64, total: u64) -> bool {
if let Some(pb) = PROGRESS_INSTANCE.lock().unwrap().as_ref() {
pb.set_position(current / total * 100_u64);
}
false
}

fn on_transcribe_progress(progress: i32) {
Expand All @@ -45,12 +45,12 @@ fn on_transcribe_progress(progress: i32) {
}

fn on_new_segment(data: SegmentCallbackData) {
let utternace: Segment = Segment {
let segment: Segment = Segment {
start: data.start_timestamp,
stop: data.end_timestamp,
text: data.text,
};
println!("{}", utternace.as_text());
println!("{}", segment.as_text());
}

fn on_abort_callback() -> bool {
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn main() -> Result<()> {
pb.reset_eta();

let args = vibe::config::ModelArgs {
lang: args.lang.map(|a| a.as_str().to_string()),
lang: Some(args.lang),
model: vibe::config::get_model_path()?,
path: PathBuf::from(args.path),
n_threads: args.n_threads,
Expand Down
5 changes: 2 additions & 3 deletions core/src/audio/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use eyre::{OptionExt, Result};
use ffmpeg_next::{codec, filter, format, frame, media};
use log::debug;
use std::path::Path;

pub fn filter(spec: &str, decoder: &codec::decoder::Audio, encoder: &codec::encoder::Audio) -> Result<filter::Graph> {
Expand Down Expand Up @@ -33,7 +32,7 @@ pub fn filter(spec: &str, decoder: &codec::decoder::Audio, encoder: &codec::enco
filter.output("in", 0)?.input("out", 0)?.parse(spec)?;
filter.validate()?;

debug!("{}", filter.dump());
log::debug!("{}", filter.dump());

if let Some(codec) = encoder.codec() {
if !codec
Expand Down Expand Up @@ -86,7 +85,7 @@ pub fn transcoder<P: AsRef<Path>>(
let context = ffmpeg_next::codec::context::Context::from_parameters(output.parameters())?;
let mut encoder = context.encoder().audio()?;

debug!("decoder channel layout is {}", decoder.channel_layout().channels());
log::debug!("decoder channel layout is {}", decoder.channel_layout().channels());
if global {
encoder.set_flags(ffmpeg_next::codec::flag::Flags::GLOBAL_HEADER);
}
Expand Down
14 changes: 6 additions & 8 deletions core/src/audio/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use eyre::{bail, Context, Result};
use ffmpeg_next::Rescale;
use hound::{SampleFormat, WavReader};
use log::debug;
use std::path::PathBuf;
mod encoder;

Expand All @@ -11,7 +10,7 @@ pub fn normalize(input: PathBuf, output: PathBuf, seek: String) -> Result<()> {
let filter = "anull";
let seek = seek.parse::<i64>().ok();

debug!("input is {} and output is {}", input.display(), output.display());
log::debug!("input is {} and output is {}", input.display(), output.display());
let mut ictx = ffmpeg_next::format::input(&input)?;
let mut octx = ffmpeg_next::format::output(&output)?;
let mut transcoder = encoder::transcoder(&mut ictx, &mut octx, &output, filter)?;
Expand Down Expand Up @@ -49,9 +48,9 @@ pub fn normalize(input: PathBuf, output: PathBuf, seek: String) -> Result<()> {
}

pub fn parse_wav_file(path: &PathBuf) -> Result<Vec<i16>> {
debug!("wav reader read from {:?}", path);
log::debug!("wav reader read from {:?}", path);
let reader = WavReader::open(path).context("failed to read file")?;
debug!("parsing {}", path.display());
log::debug!("parsing {}", path.display());

let channels = reader.spec().channels;
if reader.spec().channels != 1 {
Expand All @@ -73,7 +72,6 @@ pub fn parse_wav_file(path: &PathBuf) -> Result<Vec<i16>> {
#[cfg(test)]
mod tests {
use eyre::Result;
use log::debug;
use std::fs;
use tempfile::tempdir;

Expand All @@ -86,17 +84,17 @@ mod tests {
#[test]
fn test_audio_conversion() -> Result<()> {
init();
debug!("test");
log::debug!("test");
// Create a temporary directory to store input and output files.
let temp_dir = tempdir()?;
let input_file_path = temp_dir.path().join("input.mp3");
let output_file_path = temp_dir.path().join("output.wav");

// Copy a sample input file to the temporary directory.
debug!("copying from {} to {}", "src/audio/test_audio.wav", input_file_path.display());
log::debug!("copying from {} to {}", "src/audio/test_audio.wav", input_file_path.display());
fs::copy("src/audio/test_audio.wav", &input_file_path)?;
audio::normalize(input_file_path, output_file_path.clone(), "0".to_owned())?;
debug!("check output at {}", output_file_path.display());
log::debug!("check output at {}", output_file_path.display());

Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ mod tests {
let _ = env_logger::builder().is_test(true).try_init();
}

async fn on_download_progress(_: u64, _: u64) {}
fn on_download_progress(_: u64, _: u64) -> bool {
false
}

#[tokio::test]
async fn test_download() -> Result<()> {
Expand Down
Loading

0 comments on commit f49021c

Please sign in to comment.