summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-11-29 15:40:55 +0100
committerSanto Cariotti <santo@dcariotti.me>2024-11-29 15:40:55 +0100
commit4e589cf53de08e3689ab5c62ca7efe90f4ac9f48 (patch)
tree4f5dec66ba2b17e71ce2211ad1613bdbbbabed22
parent423442a82838b87f032d1321ff0f886617c68053 (diff)
Set audio folder
-rw-r--r--Dockerfile3
-rw-r--r--docker-compose.yml1
-rw-r--r--src/audio.rs5
-rw-r--r--src/config.rs3
4 files changed, 10 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile
index c06b5f2..c8af9eb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,6 +17,9 @@ RUN apt-get update && apt-get install -y libssl-dev ca-certificates
RUN groupadd -g 999 appuser && \
useradd -r -u 999 -g appuser appuser
+RUN mkdir -p /app/assets
+RUN chown -R appuser:appuser /app/assets
+
USER appuser
COPY --from=builder /app/target/release/cas /app
diff --git a/docker-compose.yml b/docker-compose.yml
index 9291d91..211f18e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -31,6 +31,7 @@ services:
- ALLOWED_HOST=${ALLOWED_HOST}
- EXPO_ACCESS_TOKEN=${EXPO_ACCESS_TOKEN}
- UNREALSPEECH_TOKEN=${UNREALSPEECH_TOKEN}
+ - AUDIO_PATH=${AUDIO_PATH}
depends_on:
- postgres
diff --git a/src/audio.rs b/src/audio.rs
index a67f3da..961af4a 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -14,7 +14,6 @@ use std::{
pub async fn tts(text: String, filename: String) -> Result<(), String> {
let url = "https://api.v7.unrealspeech.com/stream";
let api_key = format!("Bearer {}", CONFIG.unrealspeech_token);
- let filepath = format!("./assets/sounds/{}", filename);
// Request JSON body
let body = serde_json::json!({
@@ -45,6 +44,8 @@ pub async fn tts(text: String, filename: String) -> Result<(), String> {
// Check for successful response
if response.status().is_success() {
+ let filepath = format!("{}/{}", CONFIG.audio_path, filename);
+
let mut file = File::create(filepath).unwrap();
let content = response.bytes().await.unwrap();
let _ = file.write_all(&content);
@@ -75,7 +76,7 @@ pub async fn show_file(
);
}
- let file_name = format!("./assets/sounds/{}", id);
+ let file_name = format!("{}/{}", CONFIG.audio_path, id);
let file_path = StdPath::new(&file_name);
if !file_path.exists() {
diff --git a/src/config.rs b/src/config.rs
index 763b852..11c46e8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -22,6 +22,9 @@ pub struct Configuration {
/// Token used for text-to-speach API
pub unrealspeech_token: String,
+
+ /// Audio folder path
+ pub audio_path: String,
}
impl Configuration {