1
1
from fastapi import FastAPI , Query , HTTPException
2
2
from typing import List , Optional , Dict , Any , Union
3
3
from pydantic import BaseModel
4
- from tts_wrapper import PollyTTS , PollyClient , GoogleTTS , GoogleClient , MicrosoftTTS , MicrosoftClient , WatsonTTS , WatsonClient , ElevenLabsTTS , ElevenLabsClient , WitAiTTS , WitAiClient , MMSTTS , MMSClient
4
+ from tts_wrapper import PollyTTS , PollyClient , GoogleTTS , GoogleClient , MicrosoftTTS , MicrosoftClient , WatsonTTS , WatsonClient , ElevenLabsTTS , ElevenLabsClient , WitAiTTS , WitAiClient , SherpaOnnxTTS , SherpaOnnxClient
5
5
import os
6
6
import json
7
7
from datetime import datetime , timedelta
20
20
cache = {}
21
21
22
22
# List of engines for dropdown - we update this im main
23
- engines_list = ["polly" , "google" , "microsoft" , "watson" , "elevenlabs" , "witai" , "mms " ]
23
+ engines_list = ["polly" , "google" , "microsoft" , "watson" , "elevenlabs" , "witai" , "sherpaonnx " ]
24
24
25
25
26
26
def load_tts_engines (directory ):
@@ -137,9 +137,9 @@ def get_client(engine: str):
137
137
token = os .getenv ('WITAI_TOKEN' )
138
138
logger .info (f"WitAi Token: { token } " )
139
139
return WitAiClient (credentials = (token ))
140
- elif engine == 'mms ' :
141
- logger .info ("Creating MMS client" )
142
- return MMSClient ()
140
+ elif engine == 'sherpaonnx ' :
141
+ logger .info ("Creating SherpaOnnx client" )
142
+ return SherpaOnnxClient ()
143
143
else :
144
144
logger .error (f"Invalid engine: { engine } " )
145
145
return None
@@ -158,8 +158,8 @@ def get_tts(engine: str):
158
158
return ElevenLabsTTS (client )
159
159
elif engine == 'witai' :
160
160
return WitAiTTS (client )
161
- elif engine == 'mms ' :
162
- return MMSTTS (client )
161
+ elif engine == 'sherpaonnx ' :
162
+ return SherpaOnnxTTS (client )
163
163
else :
164
164
return None
165
165
@@ -194,6 +194,7 @@ def get_cached_voices(engine: str):
194
194
def get_voices (engine : Optional [str ] = Query (None , enum = engines_list ), lang_code : Optional [str ] = None , lang_name : Optional [str ] = None , name : Optional [str ] = None , gender : Optional [str ] = None , page : Optional [int ] = 1 , page_size : Optional [int ] = 50 , ignore_cache : Optional [bool ] = False ):
195
195
voices = []
196
196
if engine :
197
+ print (f"Fetching voices for engine as engine exists: { engine } " )
197
198
if not ignore_cache :
198
199
voices = get_cached_voices (engine .lower ())
199
200
if not voices :
@@ -202,8 +203,11 @@ def get_voices(engine: Optional[str] = Query(None, enum=engines_list), lang_code
202
203
cache_voices (engine .lower (), voices )
203
204
else :
204
205
for eng in engines_list :
206
+ print (f"Fetching voices for engine: { eng } " )
205
207
if not ignore_cache :
206
208
eng_voices = get_cached_voices (eng )
209
+ if eng == 'SherpaOnnx' :
210
+ print (f"Eng voices: { eng_voices } " )
207
211
if not eng_voices :
208
212
try :
209
213
eng_voices = load_voices_from_source (eng )
0 commit comments