File size: 916 Bytes
4ddd98f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

import { client } from "@gradio/client"

import { convertMp3ToWavBase64 } from "../utils/convertMp3ToWavBase64.mts"

const instances: string[] = [
  `${process.env.VC_SPEECH_TO_TEXT_SPACE_API_URL_1 || ""}`,
].filter(instance => instance?.length > 0)

export async function speechToText(sound: string): Promise<string> {

  const instance = instances.shift()
  instances.push(instance)

  const api = await client(instance, {
    hf_token: `${process.env.VC_HF_API_TOKEN}` as any
  })

  console.log("/speechToText: calling Space..")

  // TODO try a wav? audio/wav
  const wav = await convertMp3ToWavBase64(sound)

  // const input = sound
  // const input = Buffer.from(sound, "base64")
  // const input = new Blob([sound], { type: 'audio/mpeg' })
  const input = new Blob([wav], { type: 'audio/wav' })

  const result = await api.predict("/transcribe", [
    input,
  ])

  console.log(result)

  return "TODO"

}