Skip to content

Commit 0438555

Browse files
author
Attila Ujj
committed
BOT-2154 SPEECH: Sanitize TTS Text and Download Filenames
1 parent 43a8199 commit 0438555

File tree

7 files changed

+87
-39
lines changed

7 files changed

+87
-39
lines changed

docker-compose-picotts.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
ports:
99
- 80:80
1010
frontend:
11+
build:
12+
context: frontend
1113
image: botium/botium-speech-frontend:latest
1214
restart: always
1315
environment:
@@ -16,22 +18,22 @@ services:
1618
BOTIUM_SPEECH_PROVIDER_STT: kaldi
1719
volumes:
1820
- "./frontend/resources:/app/resources"
19-
watcher:
20-
image: botium/botium-speech-watcher:latest
21-
restart: always
22-
volumes:
23-
- "./watcher:/app/watch"
24-
- "./logs/watcher:/app/logs"
25-
stt-en:
26-
image: botium/botium-speech-kaldi-en:latest
27-
restart: always
28-
volumes:
29-
- "./logs/stt-en:/opt/logs"
30-
stt-de:
31-
image: botium/botium-speech-kaldi-de:latest
32-
restart: always
33-
volumes:
34-
- "./logs/stt-de:/opt/logs"
35-
dictate:
36-
image: botium/botium-speech-dictate:latest
37-
restart: always
21+
# watcher:
22+
# image: botium/botium-speech-watcher:latest
23+
# restart: always
24+
# volumes:
25+
# - "./watcher:/app/watch"
26+
# - "./logs/watcher:/app/logs"
27+
# stt-en:
28+
# image: botium/botium-speech-kaldi-en:latest
29+
# restart: always
30+
# volumes:
31+
# - "./logs/stt-en:/opt/logs"
32+
# stt-de:
33+
# image: botium/botium-speech-kaldi-de:latest
34+
# restart: always
35+
# volumes:
36+
# - "./logs/stt-de:/opt/logs"
37+
# dictate:
38+
# image: botium/botium-speech-dictate:latest
39+
# restart: always

docker-compose-test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: '3'
2+
services:
3+
# watcher:
4+
# build:
5+
# context: watcher
6+
# image: botium/botium-speech-watcher:latest
7+
# user: 1000:1000
8+
# restart: always
9+
# volumes:
10+
# - "./watcher:/app/watch"
11+
# - "./logs/watcher:/app/logs"
12+
# frontend:
13+
# build:
14+
# context: frontend
15+
# image: botium/botium-speech-frontend:latest
16+
# user: 1000:1000
17+
# restart: always
18+
# environment:
19+
# BOTIUM_API_TOKENS:
20+
# BOTIUM_SPEECH_PROVIDER_TTS: picotts
21+
# BOTIUM_SPEECH_PROVIDER_STT: kaldi
22+
# volumes:
23+
# - "./frontend/resources:/app/resources"
24+
stt_en:
25+
build:
26+
context: stt
27+
dockerfile: Dockerfile.kaldi.en
28+
image: botium/botium-speech-kaldi-en:latest
29+
user: 1000:1000
30+
restart: always
31+
volumes:
32+
- "./logs/stt_en:/opt/logs"
33+
# dictate:
34+
# build:
35+
# context: dictate
36+
# image: botium/botium-speech-dictate:latest
37+
# user: 1000:1000
38+
# restart: always
39+
# tts:
40+
# build:
41+
# context: tts
42+
# dockerfile: Dockerfile.marytts
43+
# image: botium/botium-speech-marytts:${TAG}
44+
# restart: always

docker-compose.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ services:
1818
BOTIUM_SPEECH_GOOGLE_PRIVATE_KEY:
1919
volumes:
2020
- "./frontend/resources:/app/resources"
21-
watcher:
22-
image: botium/botium-speech-watcher:${TAG}
23-
restart: always
24-
volumes:
25-
- "./watcher:/app/watch"
26-
- "./logs/watcher:/app/logs"
27-
stt-en:
28-
image: botium/botium-speech-kaldi-en:${TAG}
29-
restart: always
30-
volumes:
31-
- "./logs/stt-en:/opt/logs"
32-
stt-de:
33-
image: botium/botium-speech-kaldi-de:${TAG}
34-
restart: always
35-
volumes:
36-
- "./logs/stt-de:/opt/logs"
21+
# watcher:
22+
# image: botium/botium-speech-watcher:${TAG}
23+
# restart: always
24+
# volumes:
25+
# - "./watcher:/app/watch"
26+
# - "./logs/watcher:/app/logs"
27+
# stt-en:
28+
# image: botium/botium-speech-kaldi-en:${TAG}
29+
# restart: always
30+
# volumes:
31+
# - "./logs/stt-en:/opt/logs"
32+
# stt-de:
33+
# image: botium/botium-speech-kaldi-de:${TAG}
34+
# restart: always
35+
# volumes:
36+
# - "./logs/stt-de:/opt/logs"
3737
tts:
3838
image: botium/botium-speech-marytts:${TAG}
3939
restart: always

frontend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules
22
package-lock.json
33
*.local
4-
resources/.cache
4+
resources/.cache_del
55
resources/.tmp
66
resources/google.json

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@google-cloud/text-to-speech": "^3.1.3",
1818
"body-parser": "^1.19.0",
1919
"cheerio": "^1.0.0-rc.5",
20+
"content-disposition": "^0.5.3",
2021
"cross-env": "^7.0.3",
2122
"debug": "^4.3.1",
2223
"dotenv-flow": "^3.2.0",

frontend/src/routes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const mkdirp = require('mkdirp')
44
const crypto = require('crypto')
55
const express = require('express')
66
const sanitize = require('sanitize-filename')
7+
const contentDisposition = require('content-disposition')
78
const { runconvert } = require('./convert/convert')
89
const { wer } = require('./utils')
910
const debug = require('debug')('botium-speech-processing-routes')
@@ -317,7 +318,7 @@ router.get('/api/tts/:language', async (req, res, next) => {
317318
const buffer = fs.readFileSync(cacheFileBuffer)
318319
debug(`Reading tts result ${cacheFileName} from cache: ${name}`)
319320
res.writeHead(200, {
320-
'Content-disposition': `attachment; filename="${name}"`,
321+
'Content-disposition': `${contentDisposition(name)}`,
321322
'Content-Length': buffer.length
322323
})
323324
return res.end(buffer)
@@ -335,7 +336,7 @@ router.get('/api/tts/:language', async (req, res, next) => {
335336
text: req.query.text
336337
})
337338
res.writeHead(200, {
338-
'Content-disposition': `attachment; filename="${name}"`,
339+
'Content-disposition': `${contentDisposition(name)}`,
339340
'Content-Length': buffer.length
340341
})
341342
res.end(buffer)

frontend/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const wer = async (text1, text2) => {
1212

1313
const ttsFilename = (text) => {
1414
const shortenedText = _.truncate(text, { length: 500 })
15-
return sanitize(shortenedText)
15+
return sanitize(shortenedText) || 'unknown'
1616
}
1717

1818
const cleanEnv = (envName) => {

0 commit comments

Comments
 (0)