Skip to content

Commit

Permalink
remove tts cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Aug 28, 2024
1 parent 47dc66b commit 5e2323a
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 @@ -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

0 comments on commit 5e2323a

Please sign in to comment.