mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Return audio file if exists
This commit is contained in:
parent
e62765c3e6
commit
e3329d0a5f
2 changed files with 28 additions and 0 deletions
|
|
@ -86,6 +86,25 @@ export const createGCSFile = (bucket: string, filename: string): File => {
|
|||
return storage.bucket(bucket).file(filename)
|
||||
}
|
||||
|
||||
export const listGCSFiles = async (
|
||||
bucket: string,
|
||||
prefix: string
|
||||
): Promise<string[]> => {
|
||||
const [files] = await storage.bucket(bucket).getFiles({
|
||||
prefix,
|
||||
})
|
||||
return files.map((file) => file.name)
|
||||
}
|
||||
|
||||
export const downloadFromBucket = async (
|
||||
bucket: string,
|
||||
filename: string
|
||||
): Promise<Buffer> => {
|
||||
const file = createGCSFile(bucket, filename)
|
||||
const [data] = await file.download()
|
||||
return data
|
||||
}
|
||||
|
||||
const updateSpeech = async (
|
||||
speechId: string,
|
||||
token: string,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,15 @@ export class RealisticTextToSpeech implements TextToSpeech {
|
|||
// audio file to be saved in GCS
|
||||
const audioFileName = `speech/${input.key}.mp3`
|
||||
const audioFile = createGCSFile(bucket, audioFileName)
|
||||
if (await audioFile.exists()) {
|
||||
console.debug('Audio file already exists')
|
||||
const [audioData] = await audioFile.download()
|
||||
return {
|
||||
audioData,
|
||||
speechMarks: [],
|
||||
}
|
||||
}
|
||||
|
||||
const outputStream = audioFile.createWriteStream({
|
||||
resumable: true,
|
||||
}) as PassThrough
|
||||
|
|
|
|||
Loading…
Reference in a new issue