Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove tts cache #4337

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions packages/text-to-speech/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ interface HTMLInput {
bucket: string
}

interface CacheResult {
audioDataString: string
speechMarks: SpeechMark[]
}

interface Claim {
uid: string
featureName: string | null
Expand Down Expand Up @@ -283,20 +278,6 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
const ssml = `${startSsml(ssmlOptions)}${utteranceInput.text}${endSsml()}`
// hash ssml to get the cache key
const cacheKey = crypto.createHash('md5').update(ssml).digest('hex')
// find audio data in cache
const cacheResult = await redisDataSource.cacheClient.get(cacheKey)
if (cacheResult) {
console.log('Cache hit')
const { audioDataString, speechMarks }: CacheResult =
JSON.parse(cacheResult)
res.send({
idx: utteranceInput.idx,
audioData: audioDataString,
speechMarks,
})
return
}
console.log('Cache miss')

const bucket = process.env.GCS_UPLOAD_BUCKET
if (!bucket) {
Expand Down Expand Up @@ -350,24 +331,15 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
}
}

const audioDataString = audioData.toString('hex')
// save audio data to cache for 72 hours for mainly the newsletters
await redisDataSource.cacheClient.set(
cacheKey,
JSON.stringify({ audioDataString, speechMarks }),
'EX',
3600 * 72,
'NX'
)
console.log('Cache saved')

// update character count
await updateCharacterCountInRedis(
redisDataSource,
claim.uid,
characterCount
)

const audioDataString = audioData.toString('hex')

res.send({
idx: utteranceInput.idx,
audioData: audioDataString,
Expand Down
Loading