Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
[+] init
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Jan 17, 2024
0 parents commit 1dc81f9
Show file tree
Hide file tree
Showing 194 changed files with 5,509 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
30 changes: 30 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: GitHub Actions
on: [push]
jobs:
action-run:
# runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "The ${{ github.workspace }} is now ready to test your code on the runner."
- run: ls ${{ github.workspace }}
- run: sudo apt update
- run: sudo apt install libxcb-composite0-dev

- run: echo "start install Rust..."
- name: Install Rust
uses: actions-rs/toolchain@v1
- run: echo "end install Rust..."

- run: echo "start build..."
- name: Install Cargo
uses: actions-rs/cargo@v1
with:
command: build
- run: echo "end build..."
- run: echo "🍏 This job's status is ${{ job.status }}."
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cargo.lock
/target
/models
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
resolver = "2"

members = [
"vtbox",
"transcribe"
]
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2020 Tokio Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

build-evn=SLINT_STYLE=fluent
run-evn=RUST_LOG=error,warn,info,debug,sqlx=off,reqwest=off

all:
$(build-evn) cargo build --release

build:
$(build-evn) cargo build --release

build-debug:
$(build-evn) cargo build

run:
$(build-evn) $(run-evn) cargo run

run-local-debug:
$(run-evn) ./target/debug/vtbox

run-local-release:
$(run-evn) ./target/release/vtbox

test:
$(build-evn) $(run-evn) cargo test -- --nocapture

clippy:
cargo clippy

clean-incremental:
rm -rf ./target/debug/incremental/*

clean:
cargo clean

install:
cp -rf ./target/release/vtbox ~/bin/

slint-view:
slint-viewer --style fluent --auto-reload -I vtbox/ui ./vtbox/ui/appwindow.slint
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
![screenshot](./screenshot/bitbox-en.png)

[中文文档](./README.zh-CN.md)

#### Introduction
It is a remote bitcoin wallet. Using blockstream API to broadcast transaction and fetch on chain information. I test it only in bitcoin **test network**, so you take you only risk to use this bitcoin light wallet on the bitcoin man network.

#### Features
- [x] new wallet account
- [x] recover wallet account
- [x] send and receive bitcoin
- [x] show transations activity
- [x] address book

#### How to build?
- Install `Rust` and `Cargo`
- Run `make`
- Refer to [Makefile](./Makefile) for more information

#### Testnet Faucets
- https://testnet.qc.to/
- https://testnet-faucet.mempool.co/
- https://coinfaucet.eu/en/btc-testnet/
- https://bitcoinfaucet.uo1.net/
- https://onchain.io/bitcoin-testnet-faucet
- https://testnet.help/en/btcfaucet/testnet
- https://tbtc.mocacinno.com/

#### Reference
- [Slint Language Documentation](https://slint-ui.com/releases/1.0.0/docs/slint/)
- [github/slint-ui](https://github.com/slint-ui/slint)
- [Viewer for Slint](https://github.com/slint-ui/slint/tree/master/tools/viewer)
- [LSP (Language Server Protocol) Server for Slint](https://github.com/slint-ui/slint/tree/master/tools/lsp)
- [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin/)
- [decode-transaction](https://www.blockchain.com/explorer/assets/btc/decode-transaction)
- [btc testnet faucet](https://coinfaucet.eu/en/btc-testnet/)
- [bip39](https://iancoleman.io/bip39/)
- [walletsrecovery.org](https://walletsrecovery.org/)

39 changes: 39 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
![screenshot](./screenshot/bitbox-cn.png)

[English Documentation](./README.md)

#### 简介
一个remote bitcoin 钱包。使用 blockstream API 进行广播交易和获取链上信息。目前只在**测试网**进行了发送和接收BTC测试。如果你在主网使用该钱包,后果自负。

#### 功能
- [x] 生成钱包账号
- [x] 恢复钱包
- [x] 发送和接收BTC
- [x] 展示交易活动
- [x] 地址簿

#### 如何构建?
- 安装 `Rust``Cargo`
- 运行 `make`
- 参考 [Makefile](./Makefile) 了解更多信息

#### 测试网水龙头
- https://testnet.qc.to/
- https://testnet-faucet.mempool.co/
- https://coinfaucet.eu/en/btc-testnet/
- https://bitcoinfaucet.uo1.net/
- https://onchain.io/bitcoin-testnet-faucet
- https://testnet.help/en/btcfaucet/testnet
- https://tbtc.mocacinno.com/

#### 参考
- [Slint Language Documentation](https://slint-ui.com/releases/1.0.0/docs/slint/)
- [github/slint-ui](https://github.com/slint-ui/slint)
- [Viewer for Slint](https://github.com/slint-ui/slint/tree/master/tools/viewer)
- [LSP (Language Server Protocol) Server for Slint](https://github.com/slint-ui/slint/tree/master/tools/lsp)
- [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin/)
- [decode-transaction](https://www.blockchain.com/explorer/assets/btc/decode-transaction)
- [btc testnet faucet](https://coinfaucet.eu/en/btc-testnet/)
- [bip39](https://iancoleman.io/bip39/)
- [walletsrecovery.org](https://walletsrecovery.org/)

1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
Binary file added screenshot/bitbox-cn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot/bitbox-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions transcribe/.github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deployment

on:
push:
tags: [ "v*" ]

env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}

jobs:
Deploy:
name: Deploy-Crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: bump-cargo-version
shell: bash
env:
RELEASE_TAG: ${{ github.ref }}
run: |
sed -i "s/0.0.0/${RELEASE_TAG##*/\v}/g" Cargo.toml
- name: dry-run
run: cargo publish --dry-run --allow-dirty
- name: publish
run: cargo publish --allow-dirty
20 changes: 20 additions & 0 deletions transcribe/.github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Rust

on:
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 4 additions & 0 deletions transcribe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
/Cargo.lock
/models/
/test_dir
15 changes: 15 additions & 0 deletions transcribe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "transcribe"
version = "0.0.1"
edition = "2021"

[dependencies]
anyhow = "1.0"
whisper-rs = "0.10"
reqwest = { version = "0.11", features = ["json", "socks"] }
tokio = {version = "1.35", features = ["full"]}
symphonia = {version = "0.5", features=["mp3"]}

# [[bin]]
# path="examples/usage_example.rs"
# name="example"
18 changes: 18 additions & 0 deletions transcribe/examples/usage_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Result;
use transcribe::model_handler;
use transcribe::transcriber;

// "ggml-tiny.bin", "ggml-base.bin", "ggml-small.bin", "ggml-medium.bin", "ggml-large.bin",
#[tokio::main]
async fn main() -> Result<()> {
let m = model_handler::ModelHandler::new("ggml-tiny.bin", "models", None).await?;
// let m = model_handler::ModelHandler::new("ggml-tiny.bin", "models", Some(("127.0.0.1", 1084))).await?;
let trans = transcriber::Transcriber::new(m)?;
let result = trans.transcribe("src/test_data/test.mp3", None)?;
let text = result.get_text();
let start = result.get_start_timestamp();
let end = result.get_end_timestamp();
println!("start[{}]-end[{}] {}", start, end, text);

Ok(())
}
101 changes: 101 additions & 0 deletions transcribe/src/audio_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use anyhow::{anyhow, Result};
use std::fs::File;
use std::path::Path;

use symphonia::core::audio::SampleBuffer;
use symphonia::core::codecs::DecoderOptions;
use symphonia::core::errors::Error;
use symphonia::core::formats::FormatOptions;
use symphonia::core::io::MediaSourceStream;
use symphonia::core::meta::MetadataOptions;
use symphonia::core::probe::Hint;

pub fn parse_audio_file(audio_path: &str) -> Result<Vec<f32>> {
// Create a media source. Note that the MediaSource trait is automatically implemented for File,
// among other types.
let file = Box::new(File::open(Path::new(&audio_path))?);

// Create the media source stream using the boxed media source from above.
let mss = MediaSourceStream::new(file, Default::default());

// Create a hint to help the format registry guess what format reader is appropriate. In this
// example we'll leave it empty.
let hint = Hint::new();

// Use the default options when reading and decoding.
let format_opts: FormatOptions = Default::default();
let metadata_opts: MetadataOptions = Default::default();
let decoder_opts: DecoderOptions = Default::default();

// Probe the media source stream for a format.
let probed =
symphonia::default::get_probe().format(&hint, mss, &format_opts, &metadata_opts)?;

// Get the format reader yielded by the probe operation.
let mut format = probed.format;

// Get the default track.
let track = match format.default_track() {
Some(v) => v,
_ => return Err(anyhow!("get default track failed")),
};

// Create a decoder for the track.
let mut decoder = symphonia::default::get_codecs().make(&track.codec_params, &decoder_opts)?;

// Store the track identifier, we'll use it to filter packets.
let track_id = track.id;

let mut sample_buf = None;

let mut audio_data: Vec<f32> = vec![];
loop {
// Get the next packet from the format reader.
let packet = match format.next_packet() {
Ok(packet) => packet,
Err(Error::IoError(_)) => break,
Err(err) => return Err(anyhow!("{}", err)),
};
// If the packet does not belong to the selected track, skip it.
if packet.track_id() != track_id {
continue;
}

// Decode the packet into audio samples, ignoring any decode errors.
match decoder.decode(&packet) {
Ok(audio_buf) => {
// The decoded audio samples may now be accessed via the audio buffer if per-channel
// slices of samples in their native decoded format is desired. Use-cases where
// the samples need to be accessed in an interleaved order or converted into
// another sample format, or a byte buffer is required, are covered by copying the
// audio buffer into a sample buffer or raw sample buffer, respectively. In the
// example below, we will copy the audio buffer into a sample buffer in an
// interleaved order while also converting to a f32 sample format.

// If this is the *first* decoded packet, create a sample buffer matching the
// decoded audio buffer format.
if sample_buf.is_none() {
// Get the audio buffer specification.
let spec = *audio_buf.spec();

// Get the capacity of the decoded buffer. Note: This is capacity, not length!
let duration = audio_buf.capacity() as u64;

// Create the f32 sample buffer.
sample_buf = Some(SampleBuffer::<f32>::new(duration, spec));
}

if let Some(buf) = &mut sample_buf {
buf.copy_interleaved_ref(audio_buf);

// The samples may now be access via the `samples()` function.
audio_data.append(&mut buf.samples().to_vec());
}
}
Err(Error::DecodeError(_)) => (),
Err(_) => break,
}
}

Ok(audio_data)
}
3 changes: 3 additions & 0 deletions transcribe/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod audio_parser;
pub mod model_handler;
pub mod transcriber;
Loading

0 comments on commit 1dc81f9

Please sign in to comment.