Skip to content

Commit 545c504

Browse files
committed
refactor: api
1 parent b52c8c8 commit 545c504

File tree

4 files changed

+46
-386
lines changed

4 files changed

+46
-386
lines changed

apps/silero-vad-whisper-realtime-api/src/api.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
use serde::Serialize;
3-
1+
use serde::{Deserialize, Serialize};
42

53
#[derive(Debug, Serialize)]
64
pub struct TranscriptionResponse {
@@ -27,3 +25,43 @@ pub struct ErrorDetail {
2725
pub param: Option<String>,
2826
pub code: Option<String>,
2927
}
28+
29+
pub fn default_model() -> String {
30+
"whisper-1".to_string()
31+
}
32+
33+
pub fn default_response_format() -> String {
34+
"json".to_string()
35+
}
36+
37+
pub fn default_temperature() -> f32 {
38+
0.0
39+
}
40+
41+
#[derive(Debug, Deserialize)]
42+
pub struct TranscriptionRequest {
43+
/// The audio file object to transcribe
44+
/// In multipart form, this would be the file field
45+
46+
/// ID of the model to use. Only whisper-1 is currently available.
47+
#[serde(default = "default_model")]
48+
pub model: String,
49+
50+
/// The language of the input audio
51+
pub language: Option<String>,
52+
53+
/// An optional text to guide the model's style or continue a previous audio segment
54+
pub prompt: Option<String>,
55+
56+
/// The format of the transcript output
57+
#[serde(default = "default_response_format")]
58+
pub response_format: String,
59+
60+
/// The sampling temperature, between 0 and 1
61+
#[serde(default = "default_temperature")]
62+
pub temperature: f32,
63+
64+
/// Enable streaming response
65+
#[serde(default)]
66+
pub stream: bool,
67+
}

apps/silero-vad-whisper-realtime-api/src/asr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::HashMap, sync::Arc};
22

3-
use crate::api::{ErrorDetail, ErrorResponse, StreamChunk, TranscriptionResponse};
4-
use crate::{AppState, TranscriptionRequest, default_model, default_response_format, default_temperature};
3+
use crate::AppState;
4+
use crate::api::{default_model, default_response_format, default_temperature, ErrorDetail, ErrorResponse, StreamChunk, TranscriptionRequest, TranscriptionResponse};
55

66
use crate::audio_manager::AudioBuffer;
77
use anyhow::Result;

apps/silero-vad-whisper-realtime-api/src/main.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,21 @@ use axum::{
77
routing::{get, post},
88
};
99
use candle_core::Device;
10-
use serde::Deserialize;
1110
use tokio::sync::Mutex;
1211
use tower::ServiceBuilder;
1312
use tower_http::cors::CorsLayer;
1413

1514
use crate::{
16-
asr::{transcribe_audio},
15+
asr::transcribe_audio,
1716
vad::VADProcessor,
1817
whisper::{WhichWhisperModel, WhisperProcessor},
1918
};
2019

20+
mod api;
21+
mod asr;
2122
mod audio_manager;
2223
mod vad;
2324
mod whisper;
24-
mod asr;
25-
mod api;
26-
27-
#[derive(Debug, Deserialize)]
28-
pub struct TranscriptionRequest {
29-
/// The audio file object to transcribe
30-
/// In multipart form, this would be the file field
31-
32-
/// ID of the model to use. Only whisper-1 is currently available.
33-
#[serde(default = "default_model")]
34-
model: String,
35-
36-
/// The language of the input audio
37-
language: Option<String>,
38-
39-
/// An optional text to guide the model's style or continue a previous audio segment
40-
prompt: Option<String>,
41-
42-
/// The format of the transcript output
43-
#[serde(default = "default_response_format")]
44-
response_format: String,
45-
46-
/// The sampling temperature, between 0 and 1
47-
#[serde(default = "default_temperature")]
48-
temperature: f32,
49-
50-
/// Enable streaming response
51-
#[serde(default)]
52-
stream: bool,
53-
}
54-
55-
fn default_model() -> String {
56-
"whisper-1".to_string()
57-
}
58-
59-
fn default_response_format() -> String {
60-
"json".to_string()
61-
}
62-
63-
fn default_temperature() -> f32 {
64-
0.0
65-
}
66-
6725

6826
// Application state
6927
struct AppState {

0 commit comments

Comments
 (0)