Skip to content

Commit

Permalink
Merge pull request #4337 from omnivore-app/fix/remove-tts-cache
Browse files Browse the repository at this point in the history
remove tts cache
  • Loading branch information
sywhb authored Aug 30, 2024
2 parents 73753e7 + 5e2323a commit 49f9fb4
Showing 1 changed file with 2 additions and 30 deletions.
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 @@ -282,20 +277,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 @@ -347,24 +328,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

0 comments on commit 49f9fb4

Please sign in to comment.