37
37
openaiSystemPrompt string
38
38
openaiPrompt string
39
39
openaiLanguage string
40
+ openaiExt string
41
+ openaiSpeed float64
40
42
)
41
43
42
44
///////////////////////////////////////////////////////////////////////////////
@@ -59,6 +61,7 @@ func openaiRegister(flags *Flags) {
59
61
// TODO flags.Float(openaiName, "temperature", 0, "Sampling temperature to use, between 0.0 and 2.0")
60
62
flags .String (openaiName , "prompt" , "" , "An optional text to guide the model's style or continue a previous audio segment" )
61
63
//flags.String(openaiName, "language", "", "The language of the input audio in ISO-639-1 format")
64
+ flags .Float (openaiName , "speed" , 0 , "The speed of the generated audio" )
62
65
63
66
// Register commands
64
67
flags .Register (Cmd {
@@ -72,6 +75,7 @@ func openaiRegister(flags *Flags) {
72
75
{Name : "chat" , Call : openaiChat , Description : "Create a chat completion" , MinArgs : 1 , Syntax : "<text>..." },
73
76
{Name : "transcribe" , Call : openaiTranscribe , Description : "Transcribes audio into the input language" , MinArgs : 1 , MaxArgs : 1 , Syntax : "<filename>" },
74
77
{Name : "translate" , Call : openaiTranslate , Description : "Translates audio into English" , MinArgs : 1 , MaxArgs : 1 , Syntax : "<filename>" },
78
+ {Name : "say" , Call : openaiTextToSpeech , Description : "Text to speech" , MinArgs : 2 , Syntax : "<voice-id> <text>..." },
75
79
},
76
80
})
77
81
}
@@ -96,6 +100,7 @@ func openaiParse(flags *Flags, opts ...client.ClientOpt) error {
96
100
openaiSystemPrompt = flags .GetString ("system" )
97
101
openaiPrompt = flags .GetString ("prompt" )
98
102
openaiLanguage = flags .GetString ("language" )
103
+ openaiExt = flags .GetOutExt ()
99
104
100
105
if temp , err := flags .GetValue ("temperature" ); err == nil {
101
106
t := temp .(float64 )
@@ -117,6 +122,9 @@ func openaiParse(flags *Flags, opts ...client.ClientOpt) error {
117
122
v := count .(uint64 )
118
123
openaiCount = & v
119
124
}
125
+ if speed , err := flags .GetValue ("speed" ); err == nil {
126
+ openaiSpeed = speed .(float64 )
127
+ }
120
128
121
129
// Return success
122
130
return nil
@@ -274,6 +282,7 @@ func openaiTranscribe(ctx context.Context, w *tablewriter.Writer, args []string)
274
282
275
283
func openaiTranslate (ctx context.Context , w * tablewriter.Writer , args []string ) error {
276
284
opts := []openai.Opt {}
285
+
277
286
if openaiModel != "" {
278
287
opts = append (opts , openai .OptModel (openaiModel ))
279
288
}
@@ -303,3 +312,33 @@ func openaiTranslate(ctx context.Context, w *tablewriter.Writer, args []string)
303
312
// Write output
304
313
return w .Write (transcription )
305
314
}
315
+
316
+ func openaiTextToSpeech (ctx context.Context , w * tablewriter.Writer , args []string ) error {
317
+ opts := []openai.Opt {}
318
+
319
+ // Set response format
320
+ if openaiResponseFormat != "" {
321
+ opts = append (opts , openai .OptResponseFormat (openaiResponseFormat ))
322
+ } else if openaiExt != "" {
323
+ opts = append (opts , openai .OptResponseFormat (openaiExt ))
324
+ }
325
+
326
+ // Set other options
327
+ if openaiSpeed > 0 {
328
+ opts = append (opts , openai .OptSpeed (float32 (openaiSpeed )))
329
+ }
330
+
331
+ // The text to speak
332
+ voice := args [0 ]
333
+ text := strings .Join (args [1 :], " " )
334
+
335
+ // Request -> Response
336
+ if n , err := openaiClient .TextToSpeech (ctx , w .Output (), voice , text , opts ... ); err != nil {
337
+ return err
338
+ } else {
339
+ openaiClient .Debugf ("wrote %v bytes" , n )
340
+ }
341
+
342
+ // Return success
343
+ return nil
344
+ }
0 commit comments