Use a voice mapping

This commit is contained in:
Jackson Harper
2023-02-16 15:43:12 +08:00
parent 9d5cb84648
commit cd9c2e50b5

View File

@ -5,11 +5,41 @@ import {
} from './textToSpeech'
import axios from 'axios'
const getRealisticVoiceId = (name: string | undefined) => {
const voiceList = [
{
voiceId: '21m00Tcm4TlvDq8ikWAM',
name: 'Rachel',
},
{
voiceId: 'EXAVITQu4vr4xnSDxMaL',
name: 'Bella',
},
{
voiceId: 'MF3mGyEYCl7XYWbV9V6O',
name: 'Elli',
},
{
voiceId: 'TxGEqnHWrfWFTfGW9XjX',
name: 'Josh',
},
{
voiceId: 'VR6AewLTigWG4xSOukaG',
name: 'Arnold',
},
{
voiceId: 'pNInz6obpgDQGcFmaJgB',
name: 'Adam',
},
]
return voiceList.find((voice) => voice.name === name)?.voiceId
}
export class RealisticTextToSpeech implements TextToSpeech {
synthesizeTextToSpeech = async (
input: TextToSpeechInput
): Promise<TextToSpeechOutput> => {
const voiceId = process.env.REALISTIC_VOICE_ID
const voiceId = getRealisticVoiceId(input.voice)
const apiKey = process.env.REALISTIC_VOICE_API_KEY
const apiEndpoint = process.env.REALISTIC_VOICE_API_ENDPOINT