Coder Social home page Coder Social logo

rsnowboy's Introduction

rsnowboy

Build Status

This repo is snowboy wrapper for rust.

Snowboy is created by C++, But rust does not covert all data to C++, So this crate is Snowoby for rust wrapper.

The more document you can see snowboy and kitt.ai

Usage

[dependencies]
rsnowboy = { version = "0.1", git = "https://github.com/fewensa/rsnowboy" }

crates.io

Because crates.io has a limitation

crates.io currently has a 10MB size limit on the .crate file.

So now the new version isn't publish to crates.io. The old version (0.1.0) is also can be use. but not compile itself.

Examples

use rsnowboy::SnowboyDetect;

fn main() {
  let resource_filename = "resources/common.res";
  let model_filename = "resources/models/snowboy.umdl";
  let sensitivity_str = "1";
  let audio_gain = 1 as f32;
  let apply_frontend = false;

  let detector = SnowboyDetect::new(resource_filename, model_filename);

  detector.set_sensitivity(sensitivity_str);
  detector.set_audio_gain(audio_gain);
  detector.apply_frontend(apply_frontend);

  let mut rec_count = 0;
  let mut sil_count = 0;
  let mut save_buffer: Vec<i16> = Vec::new();

  // loop get voice
//  loop {
    let mut voice = voice(); // get voice from your device
    let result = detector.run_short_array_detection(voice.as_ptr(), voice.len() as i32, false);

    match result {
      0 => {
        println!("voice");
        save_buffer.append(voice.as_mut());
        rec_count += 1;
        sil_count = 0;
      }
      1 => {
        println!("Hotword {} detected!", result);
        // play resources/ding.wav
        save_buffer.clear();
        rec_count = 1;
      }
      -2 => {
        println!("silence");
        save_buffer.append(voice.as_mut());
        sil_count += 1;

        if rec_count > 0 {
          save_buffer.append(voice.as_mut());
          sil_count += 1;
          println!("silence");
        }

        if sil_count > 2 && rec_count > 1 {
          /*
          play resources/dong.wav
          There you can write `save_buffer` to wave file, and use any speech to text service convert this voice
          file to text, and do any thing.
          */
          rec_count = 0;
          sil_count = 0;
          save_buffer.clear();
          println!("Listening...");
        }
      }
      _ => {}
    }

//  }

}

fn voice() -> Vec<i16> {
  vec![
    -11, -12, -10, -20, -15, -5, 2, 5, 8,
    10, 12, 14, 13, 20, 25, 14, 12, 9, 12,
    -1, -5, 20, 22, 24, 24, 14, 10, 15, 11
  ]
}

Notice

Because snowboy dependency gsl, so you need install libgsl to your system

rsnowboy's People

Contributors

fewensa avatar sheosi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.