4
4
"context"
5
5
"log"
6
6
"os"
7
+ "strconv"
7
8
"time"
8
9
9
10
"github.com/AgoraIO-Community/agora-rest-client-go/agora/auth"
@@ -34,7 +35,7 @@ func (s *Service) SetCredential(username string, password string) {
34
35
s .credential = auth .NewBasicAuthCredential (username , password )
35
36
}
36
37
37
- func (s * Service ) RunWithCustomTTS (ttsVendor req. TTSVendor , ttsParam req.TTSVendorParamsInterface ) {
38
+ func (s * Service ) RunWithCustomTTS (ttsParam req.TTSVendorParamsInterface ) {
38
39
ctx := context .Background ()
39
40
config := & convoai.Config {
40
41
AppID : s .appId ,
@@ -114,7 +115,7 @@ func (s *Service) RunWithCustomTTS(ttsVendor req.TTSVendor, ttsParam req.TTSVend
114
115
GreetingMessage : "Hello,how can I help you?" ,
115
116
},
116
117
TTS : & req.JoinPropertiesTTSBody {
117
- Vendor : ttsVendor ,
118
+ Vendor : ttsParam . GetVendorType () ,
118
119
Params : ttsParam ,
119
120
},
120
121
Vad : & req.JoinPropertiesVadBody {
@@ -320,7 +321,7 @@ func (s *Service) RunWithBytedanceTTS() {
320
321
PitchRatio : 1.0 ,
321
322
Emotion : "happy" ,
322
323
}
323
- s .RunWithCustomTTS (req . BytedanceTTSVendor , ttsParam )
324
+ s .RunWithCustomTTS (ttsParam )
324
325
}
325
326
326
327
func (s * Service ) RunWithTencentTTS () {
@@ -349,7 +350,7 @@ func (s *Service) RunWithTencentTTS() {
349
350
EmotionCategory : "happy" ,
350
351
EmotionIntensity : 100 ,
351
352
}
352
- s .RunWithCustomTTS (req . TencentTTSVendor , ttsParam )
353
+ s .RunWithCustomTTS (ttsParam )
353
354
}
354
355
355
356
func (s * Service ) RunWithMinimaxTTS () {
@@ -384,7 +385,7 @@ func (s *Service) RunWithMinimaxTTS() {
384
385
},
385
386
}
386
387
387
- s .RunWithCustomTTS (req . MinimaxTTSVendor , ttsParam )
388
+ s .RunWithCustomTTS (ttsParam )
388
389
}
389
390
390
391
func (s * Service ) RunWithMicrosoftTTS () {
@@ -412,7 +413,7 @@ func (s *Service) RunWithMicrosoftTTS() {
412
413
SampleRate : 24000 ,
413
414
}
414
415
415
- s .RunWithCustomTTS (req . MicrosoftTTSVendor , ttsParam )
416
+ s .RunWithCustomTTS (ttsParam )
416
417
}
417
418
418
419
func (s * Service ) RunWithElevenLabsTTS () {
@@ -437,5 +438,80 @@ func (s *Service) RunWithElevenLabsTTS() {
437
438
VoiceId : ttsVoiceId ,
438
439
}
439
440
440
- s .RunWithCustomTTS (req .ElevenLabsTTSVendor , ttsParam )
441
+ s .RunWithCustomTTS (ttsParam )
442
+ }
443
+
444
+ func (s * Service ) RunWithCartesiaTTS () {
445
+ ttsApiKey := os .Getenv ("CONVOAI_TTS_CARTESIA_API_KEY" )
446
+ if ttsApiKey == "" {
447
+ log .Fatalln ("CONVOAI_TTS_CARTESIA_API_KEY is required" )
448
+ }
449
+
450
+ ttsModelId := os .Getenv ("CONVOAI_TTS_CARTESIA_MODEL_ID" )
451
+ if ttsModelId == "" {
452
+ log .Fatalln ("CONVOAI_TTS_CARTESIA_MODEL_ID is required" )
453
+ }
454
+
455
+ ttsVoiceMode := os .Getenv ("CONVOAI_TTS_CARTESIA_VOICE_MODE" )
456
+ if ttsVoiceMode == "" {
457
+ log .Fatalln ("CONVOAI_TTS_CARTESIA_VOICE_MODE is required" )
458
+ }
459
+
460
+ ttsVoiceId := os .Getenv ("CONVOAI_TTS_CARTESIA_VOICE_ID" )
461
+ if ttsVoiceId == "" {
462
+ log .Fatalln ("CONVOAI_TTS_CARTESIA_VOICE_ID is required" )
463
+ }
464
+
465
+ ttsParam := req.TTSCartesiaVendorParams {
466
+ APIKey : ttsApiKey ,
467
+ ModelId : ttsModelId ,
468
+ Voice : & req.TTSCartesiaVendorVoice {
469
+ Mode : ttsVoiceMode ,
470
+ Id : ttsVoiceId ,
471
+ },
472
+ }
473
+
474
+ s .RunWithCustomTTS (ttsParam )
475
+ }
476
+
477
+ func (s * Service ) RunWithOpenAITTS () {
478
+ ttsApiKey := os .Getenv ("CONVOAI_TTS_OPENAI_API_KEY" )
479
+ if ttsApiKey == "" {
480
+ log .Fatalln ("CONVOAI_TTS_OPENAI_API_KEY is required" )
481
+ }
482
+
483
+ ttsModel := os .Getenv ("CONVOAI_TTS_OPENAI_MODEL" )
484
+ if ttsModel == "" {
485
+ log .Fatalln ("CONVOAI_TTS_OPENAI_MODEL is required" )
486
+ }
487
+
488
+ ttsVoice := os .Getenv ("CONVOAI_TTS_OPENAI_VOICE" )
489
+ if ttsVoice == "" {
490
+ log .Fatalln ("CONVOAI_TTS_OPENAI_VOICE is required" )
491
+ }
492
+
493
+ ttsInstructions := os .Getenv ("CONVOAI_TTS_OPENAI_INSTRUCTIONS" )
494
+ if ttsInstructions == "" {
495
+ log .Fatalln ("CONVOAI_TTS_OPENAI_INSTRUCTIONS is required" )
496
+ }
497
+
498
+ ttsSpeed := os .Getenv ("CONVOAI_TTS_OPENAI_SPEED" )
499
+ if ttsSpeed == "" {
500
+ log .Fatalln ("CONVOAI_TTS_OPENAI_SPEED is required" )
501
+ }
502
+
503
+ speed , err := strconv .ParseFloat (ttsSpeed , 32 )
504
+ if err != nil {
505
+ log .Fatalln ("CONVOAI_TTS_OPENAI_SPEED is not a valid float" )
506
+ }
507
+
508
+ ttsParam := req.TTSOpenAIVendorParams {
509
+ APIKey : ttsApiKey ,
510
+ Model : ttsModel ,
511
+ Voice : ttsVoice ,
512
+ Instructions : ttsInstructions ,
513
+ Speed : float32 (speed ),
514
+ }
515
+
516
+ s .RunWithCustomTTS (ttsParam )
441
517
}
0 commit comments