Skip to content

Commit

Permalink
refactor: move normalizeTextForTTS para o modulo de TTS
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoid committed Dec 8, 2024
1 parent b2da66a commit ef099e5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
38 changes: 0 additions & 38 deletions lib/modules/recordings/recordings.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,3 @@ export const deleteRecording = async (id: number) => {

await repository.delete(id)
}

const acronymLetterToWord: Record<string, string> = {
A: 'á',
B: 'bê',
C: 'cê',
D: 'dê',
E: 'é',
F: 'éfe',
G: 'gê',
H: 'agá',
I: 'í',
J: 'jóta',
K: 'cá',
L: 'éle',
M: 'ême',
N: 'êne',
O: 'ó',
P: 'pê',
Q: 'quê',
R: 'érre',
S: 'ésse',
T: 'tê',
U: 'ú',
V: 'vê',
W: 'dábliu',
X: 'xís',
Y: 'ípisilon',
Z: 'zê',
}

export const normalizeTextForTTS = (text: string) => {
return text.replaceAll(/(^| |\()(?:[A-Z]){2,}/gm, (acronym) =>
acronym
.split('')
.map((char) => acronymLetterToWord[char] ?? char)
.join(''),
)
}
39 changes: 38 additions & 1 deletion lib/modules/tts/tts.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createReadStream, createWriteStream } from 'fs'
import pRetry from 'p-retry'
import { RETRY_OPTIONS } from '../../constants'
import { normalizeTextForTTS } from '../recordings/recordings.utils'
import { finished } from 'stream/promises'
import { Readable } from 'node:stream'
import { ReadableStream } from 'stream/web'
Expand Down Expand Up @@ -38,6 +37,44 @@ const buildTtsUrl = (
return url
}

const acronymLetterToWord: Record<string, string> = {
A: 'á',
B: 'bê',
C: 'cê',
D: 'dê',
E: 'é',
F: 'éfe',
G: 'gê',
H: 'agá',
I: 'í',
J: 'jóta',
K: 'cá',
L: 'éle',
M: 'ême',
N: 'êne',
O: 'ó',
P: 'pê',
Q: 'quê',
R: 'érre',
S: 'ésse',
T: 'tê',
U: 'ú',
V: 'vê',
W: 'dábliu',
X: 'xís',
Y: 'ípisilon',
Z: 'zê',
}

export const normalizeTextForTTS = (text: string) => {
return text.replaceAll(/(^| |\()(?:[A-Z]){2,}/gm, (acronym) =>
acronym
.split('')
.map((char) => acronymLetterToWord[char] ?? char)
.join(''),
)
}

const maxChunkLength = 140
const fullStopFixCharacters = '|'
const sentenceEndRegex = /(\.|!|\?)(?:\n| |$)/
Expand Down

0 comments on commit ef099e5

Please sign in to comment.