import service from '@/xiaolanbenlib/module/axios'
import { TServiceAudioModel } from '@/types/index'
import { getTempFileContent } from "@/utils";


export type TText2SpeachReq = {
  text: string;
  voice: string;
}


// 
export const audio2Speach = (data: TText2SpeachReq) => {
  return service.post<TText2SpeachReq, {audio: string, session: string}>('/v1/audio/speech', data)
}

// 获取系统音色列表
export const getSysVoiceList = () => {
  return service.get<TServiceAudioModel[]>('/v1/audio/voice')
}

// 试听音色
export const voiceTryout = (voice: string, configs?:any) => {
  return service.get<{audio: string, session: string}>(`/v1/audio/${voice}/tryout`, configs)
}

// asr 语音识别
export const audioRecognition = async (tmpPath: string, format: string = 'mp3') => {
  
  const content = await getTempFileContent<number>(tmpPath, 'base64')
  return service.post<{data: number, format:string}, {text:string, duration: number}>(`/v1/audio/asr`, {data: content, format})
}