move "use"
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -1,14 +1,19 @@
|
|||||||
use std::process::exit;
|
|
||||||
|
|
||||||
static PID_FILE: &str = "/tmp/ffmpeg_audio_recording.pid";
|
static PID_FILE: &str = "/tmp/ffmpeg_audio_recording.pid";
|
||||||
static TEMP_FILE: &str = "/tmp/ffmpeg_audio_recording.ogg";
|
static TEMP_FILE: &str = "/tmp/ffmpeg_audio_recording.ogg";
|
||||||
static API_ENDPOINT: &str = "http://127.0.0.1:5000/v1/audio/transcriptions";
|
static API_ENDPOINT: &str = "http://127.0.0.1:5000/v1/audio/transcriptions";
|
||||||
static AUTH_TOKEN: &str = "woshimima";
|
static AUTH_TOKEN: &str = "woshimima";
|
||||||
|
|
||||||
|
use clipboard::ClipboardContext;
|
||||||
|
use clipboard::ClipboardProvider;
|
||||||
use ctrlc;
|
use ctrlc;
|
||||||
use nix::sys::signal;
|
use nix::sys::signal;
|
||||||
use nix::sys::signal::Signal;
|
use nix::sys::signal::Signal;
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
|
use reqwest::blocking::Client;
|
||||||
|
use std::fs;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::process::exit;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -33,12 +38,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn upload_audio() -> String {
|
fn upload_audio() -> String {
|
||||||
use reqwest::blocking::Client;
|
|
||||||
|
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
|
|
||||||
let form = reqwest::blocking::multipart::Form::new()
|
let form = reqwest::blocking::multipart::Form::new()
|
||||||
.file("file", TEMP_FILE).unwrap()
|
.file("file", TEMP_FILE)
|
||||||
|
.unwrap()
|
||||||
.text("response_format", "text")
|
.text("response_format", "text")
|
||||||
.text("prompt", get_clipboard_content())
|
.text("prompt", get_clipboard_content())
|
||||||
.text("model", "whisper-1");
|
.text("model", "whisper-1");
|
||||||
@@ -87,13 +91,9 @@ fn start_recording() {
|
|||||||
ffmpeg.wait().unwrap();
|
ffmpeg.wait().unwrap();
|
||||||
|
|
||||||
println!("ffmpeg exited");
|
println!("ffmpeg exited");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_pid() -> Option<String> {
|
fn read_pid() -> Option<String> {
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
let mut file = match File::open(PID_FILE) {
|
let mut file = match File::open(PID_FILE) {
|
||||||
Ok(ctx) => ctx,
|
Ok(ctx) => ctx,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -110,23 +110,19 @@ fn read_pid() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn kill_and_delete_pid() {
|
fn kill_and_delete_pid() {
|
||||||
use std::fs;
|
|
||||||
let pid = read_pid().unwrap();
|
let pid = read_pid().unwrap();
|
||||||
let pid = pid.trim();
|
let pid = pid.trim();
|
||||||
let pid = pid.parse::<i32>().unwrap();
|
let pid = pid.parse::<i32>().unwrap();
|
||||||
match signal::kill(Pid::from_raw(pid), Signal::SIGINT) {
|
match signal::kill(Pid::from_raw(pid), Signal::SIGINT) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
send_notification("Error to kill", "Error to kill pid, cleaning");
|
send_notification("Error to kill", "Error to kill pid, cleaning");
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
fs::remove_file(PID_FILE).unwrap();
|
fs::remove_file(PID_FILE).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pid() {
|
fn set_pid() {
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
let mut file = File::create(PID_FILE).unwrap();
|
let mut file = File::create(PID_FILE).unwrap();
|
||||||
file.write_all(format!("{}", std::process::id()).as_bytes())
|
file.write_all(format!("{}", std::process::id()).as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -148,9 +144,6 @@ fn send_notification(title: &str, content: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_clipboard_content() -> String {
|
fn get_clipboard_content() -> String {
|
||||||
use clipboard::ClipboardContext;
|
|
||||||
use clipboard::ClipboardProvider;
|
|
||||||
|
|
||||||
match ClipboardContext::new().and_then(|mut ctx| ctx.get_contents()) {
|
match ClipboardContext::new().and_then(|mut ctx| ctx.get_contents()) {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@@ -164,9 +157,6 @@ fn get_clipboard_content() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_clipboard_content(content: &str) {
|
fn set_clipboard_content(content: &str) {
|
||||||
use clipboard::ClipboardContext;
|
|
||||||
use clipboard::ClipboardProvider;
|
|
||||||
|
|
||||||
match ClipboardContext::new().and_then(|mut ctx| ctx.set_contents(content.to_owned())) {
|
match ClipboardContext::new().and_then(|mut ctx| ctx.set_contents(content.to_owned())) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user