From cd9c2e50b55519926229bfef0f7a1a52d4d1a923 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 16 Feb 2023 15:43:12 +0800 Subject: [PATCH] Use a voice mapping --- .../src/realisticTextToSpeech.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/text-to-speech/src/realisticTextToSpeech.ts b/packages/text-to-speech/src/realisticTextToSpeech.ts index fa3e99159..c19c293a6 100644 --- a/packages/text-to-speech/src/realisticTextToSpeech.ts +++ b/packages/text-to-speech/src/realisticTextToSpeech.ts @@ -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 => { - 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