Skip to content

Commit 28ad865

Browse files
committed
fix(groq-tts): unify TTS format and voice casting for Groq SDK
- Assign default values before type assertion to avoid unnecessary conditionals - Use a single variable `voiceFormat` for GroqTTSFormat and reuse in request - Remove redundant casts in `SpeechCreateParams` to satisfy ESLint - Maintain type safety between TTSVoice/GroqTTSVoice and TTSFormat/GroqTTSFormat
1 parent 1946804 commit 28ad865

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/typescript/ai-groq/src/adapters/tts.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,24 @@ export class GroqTTSAdapter<TModel extends GroqTTSModel> extends BaseTTSAdapter<
4646
async generateSpeech(
4747
options: TTSOptions<GroqTTSProviderOptions>,
4848
): Promise<TTSResult> {
49-
const { model, text, voice, format, speed, modelOptions } = options
49+
const {
50+
model,
51+
text,
52+
voice = 'autumn',
53+
format = 'wav',
54+
speed,
55+
modelOptions,
56+
} = options
5057

5158
validateAudioInput({ input: text, model })
5259

60+
const voiceFormat = format as GroqTTSFormat
61+
5362
const request: Groq_SDK.Audio.Speech.SpeechCreateParams = {
5463
model,
5564
input: text,
56-
voice: (voice as GroqTTSVoice) || 'autumn',
57-
response_format: (format as GroqTTSFormat) || 'wav',
65+
voice: voice as GroqTTSVoice,
66+
response_format: voiceFormat,
5867
speed,
5968
...modelOptions,
6069
}
@@ -64,14 +73,13 @@ export class GroqTTSAdapter<TModel extends GroqTTSModel> extends BaseTTSAdapter<
6473
const arrayBuffer = await response.arrayBuffer()
6574
const base64 = Buffer.from(arrayBuffer).toString('base64')
6675

67-
const outputFormat = format || 'wav'
68-
const contentType = this.getContentType(outputFormat)
76+
const contentType = this.getContentType(voiceFormat)
6977

7078
return {
7179
id: generateId(this.name),
7280
model,
7381
audio: base64,
74-
format: outputFormat,
82+
format: voiceFormat,
7583
contentType,
7684
}
7785
}

packages/typescript/ai-groq/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type {
3333
// Types
3434
export type {
3535
GroqChatModelProviderOptionsByName,
36+
GroqTTSModelProviderOptionsByName,
3637
GroqModelInputModalitiesByName,
3738
ResolveProviderOptions,
3839
ResolveInputModalities,

0 commit comments

Comments
 (0)