@ai-sdk/fish-audio 0.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @ai-sdk/fish-audio
2
+
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - db05205: feat(fish-audio): add Fish Audio provider with speech and transcription models
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -1,5 +1,63 @@
1
- # @ai-sdk/fish-audio
1
+ # AI SDK - Fish Audio Provider
2
2
 
3
- AI SDK provider for Fish Audio.
3
+ The **[Fish Audio provider](https://ai-sdk.dev/providers/ai-sdk-providers/fish-audio)** for the [AI SDK](https://ai-sdk.dev/docs)
4
+ contains speech generation (S1 and S2 models) and speech-to-text transcription support.
4
5
 
5
- This package is maintained in the `vercel/ai` repository.
6
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access Fish Audio (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
7
+
8
+ ## Setup
9
+
10
+ The Fish Audio provider is available in the `@ai-sdk/fish-audio` module. You can install it with
11
+
12
+ ```bash
13
+ npm i @ai-sdk/fish-audio
14
+ ```
15
+
16
+ ## Skill for Coding Agents
17
+
18
+ If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:
19
+
20
+ ```shell
21
+ npx skills add vercel/ai
22
+ ```
23
+
24
+ ## Provider Instance
25
+
26
+ You can import the default provider instance `fishAudio` from `@ai-sdk/fish-audio`:
27
+
28
+ ```ts
29
+ import { fishAudio } from '@ai-sdk/fish-audio';
30
+ ```
31
+
32
+ ## Example
33
+
34
+ ### Speech generation
35
+
36
+ ```ts
37
+ import { fishAudio } from '@ai-sdk/fish-audio';
38
+ import { generateSpeech } from 'ai';
39
+
40
+ const { audio } = await generateSpeech({
41
+ model: fishAudio.speech('s1'),
42
+ text: 'Hello from Fish Audio!',
43
+ // A voice model ID from https://fish.audio, or omit for the default voice.
44
+ voice: '933563129e564b19a115bedd57b7406a',
45
+ });
46
+ ```
47
+
48
+ ### Transcription
49
+
50
+ ```ts
51
+ import { fishAudio } from '@ai-sdk/fish-audio';
52
+ import { transcribe } from 'ai';
53
+ import { readFile } from 'node:fs/promises';
54
+
55
+ const { text, segments } = await transcribe({
56
+ model: fishAudio.transcription(),
57
+ audio: await readFile('audio.mp3'),
58
+ });
59
+ ```
60
+
61
+ ## Documentation
62
+
63
+ Please check out the **[Fish Audio provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/fish-audio)** for more information.
@@ -0,0 +1,159 @@
1
+ import { SpeechModelV3, ProviderV3, TranscriptionModelV3 } from '@ai-sdk/provider';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { z } from 'zod/v4';
4
+
5
+ type FishAudioConfig = {
6
+ provider: string;
7
+ url: (options: {
8
+ modelId: string;
9
+ path: string;
10
+ }) => string;
11
+ headers?: () => Record<string, string | undefined>;
12
+ fetch?: FetchFunction;
13
+ };
14
+
15
+ /**
16
+ * Fish Audio TTS model IDs, sent via the `model` HTTP header.
17
+ *
18
+ * `s2.1-pro` is the model Fish Audio recommends by default. `s2.1-pro-free` is
19
+ * a free developer tier with no time-to-first-audio or data-processing
20
+ * guarantees, so prefer `s2.1-pro` for production use.
21
+ *
22
+ * https://docs.fish.audio/api-reference/endpoint/openapi-v1/text-to-speech
23
+ */
24
+ type FishAudioSpeechModelId = 's1' | 's2-pro' | 's2.1-pro' | 's2.1-pro-free' | (string & {});
25
+ /**
26
+ * A Fish Audio voice model ID (`reference_id`), either from the Fish Audio
27
+ * voice library or one of your own uploaded models.
28
+ */
29
+ type FishAudioSpeechVoiceId = string;
30
+
31
+ interface FishAudioSpeechModelConfig extends FishAudioConfig {
32
+ _internal?: {
33
+ currentDate?: () => Date;
34
+ };
35
+ }
36
+ declare class FishAudioSpeechModel implements SpeechModelV3 {
37
+ readonly modelId: FishAudioSpeechModelId;
38
+ private readonly config;
39
+ readonly specificationVersion = "v3";
40
+ get provider(): string;
41
+ constructor(modelId: FishAudioSpeechModelId, config: FishAudioSpeechModelConfig);
42
+ private getArgs;
43
+ doGenerate(options: Parameters<SpeechModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>>;
44
+ }
45
+
46
+ /**
47
+ * Fish Audio transcription model ID.
48
+ *
49
+ * `POST /v1/asr` currently exposes no model selector and serves a single
50
+ * model, so `transcribe-1` is a routing label rather than a wire value: it is
51
+ * not sent to the API. Fish Audio expects to add more ASR models and to select
52
+ * them with the `model` HTTP header, matching `/v1/tts`.
53
+ *
54
+ * https://docs.fish.audio/api-reference/endpoint/openapi-v1/speech-to-text
55
+ */
56
+ type FishAudioTranscriptionModelId = 'transcribe-1' | (string & {});
57
+
58
+ interface FishAudioProvider extends ProviderV3 {
59
+ (modelId: FishAudioSpeechModelId, settings?: {}): {
60
+ speech: FishAudioSpeechModel;
61
+ };
62
+ /**
63
+ * Creates a model for speech generation.
64
+ */
65
+ speech(modelId: FishAudioSpeechModelId): SpeechModelV3;
66
+ /**
67
+ * Creates a model for speech generation.
68
+ *
69
+ * Narrowed to required: Fish Audio always provides speech models.
70
+ */
71
+ speechModel(modelId: FishAudioSpeechModelId): SpeechModelV3;
72
+ /**
73
+ * Creates a model for transcription.
74
+ */
75
+ transcription(modelId?: FishAudioTranscriptionModelId): TranscriptionModelV3;
76
+ /**
77
+ * Creates a model for transcription.
78
+ *
79
+ * Narrowed to required: Fish Audio always provides a transcription model.
80
+ */
81
+ transcriptionModel(modelId?: FishAudioTranscriptionModelId): TranscriptionModelV3;
82
+ }
83
+ interface FishAudioProviderSettings {
84
+ /**
85
+ * API key for authenticating requests.
86
+ */
87
+ apiKey?: string;
88
+ /**
89
+ * Base URL for the API calls.
90
+ */
91
+ baseURL?: string;
92
+ /**
93
+ * Custom headers to include in the requests.
94
+ */
95
+ headers?: Record<string, string>;
96
+ /**
97
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
98
+ * or to provide a custom fetch implementation for e.g. testing.
99
+ */
100
+ fetch?: FetchFunction;
101
+ }
102
+ /**
103
+ * Create a Fish Audio provider instance.
104
+ */
105
+ declare function createFishAudio(options?: FishAudioProviderSettings): FishAudioProvider;
106
+ /**
107
+ * Default Fish Audio provider instance.
108
+ */
109
+ declare const fishAudio: FishAudioProvider;
110
+
111
+ interface FishAudioTranscriptionModelConfig extends FishAudioConfig {
112
+ _internal?: {
113
+ currentDate?: () => Date;
114
+ };
115
+ }
116
+ declare class FishAudioTranscriptionModel implements TranscriptionModelV3 {
117
+ readonly modelId: FishAudioTranscriptionModelId;
118
+ private readonly config;
119
+ readonly specificationVersion = "v3";
120
+ get provider(): string;
121
+ constructor(modelId: FishAudioTranscriptionModelId, config: FishAudioTranscriptionModelConfig);
122
+ private getArgs;
123
+ doGenerate(options: Parameters<TranscriptionModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>;
124
+ }
125
+
126
+ declare const fishAudioSpeechModelOptionsSchema: z.ZodObject<{
127
+ referenceId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
128
+ sampleRate: z.ZodOptional<z.ZodNumber>;
129
+ mp3Bitrate: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<64>, z.ZodLiteral<128>, z.ZodLiteral<192>]>>;
130
+ opusBitrate: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<-1000>, z.ZodLiteral<24000>, z.ZodLiteral<32000>, z.ZodLiteral<48000>, z.ZodLiteral<64000>]>>;
131
+ latency: z.ZodOptional<z.ZodEnum<{
132
+ low: "low";
133
+ normal: "normal";
134
+ balanced: "balanced";
135
+ }>>;
136
+ volume: z.ZodOptional<z.ZodNumber>;
137
+ normalizeLoudness: z.ZodOptional<z.ZodBoolean>;
138
+ temperature: z.ZodOptional<z.ZodNumber>;
139
+ topP: z.ZodOptional<z.ZodNumber>;
140
+ chunkLength: z.ZodOptional<z.ZodNumber>;
141
+ minChunkLength: z.ZodOptional<z.ZodNumber>;
142
+ normalize: z.ZodOptional<z.ZodBoolean>;
143
+ maxNewTokens: z.ZodOptional<z.ZodNumber>;
144
+ repetitionPenalty: z.ZodOptional<z.ZodNumber>;
145
+ conditionOnPreviousChunks: z.ZodOptional<z.ZodBoolean>;
146
+ earlyStopThreshold: z.ZodOptional<z.ZodNumber>;
147
+ features: z.ZodOptional<z.ZodArray<z.ZodString>>;
148
+ }, z.core.$strip>;
149
+ type FishAudioSpeechModelOptions = z.infer<typeof fishAudioSpeechModelOptionsSchema>;
150
+
151
+ declare const fishAudioTranscriptionModelOptionsSchema: z.ZodObject<{
152
+ language: z.ZodOptional<z.ZodString>;
153
+ ignoreTimestamps: z.ZodOptional<z.ZodBoolean>;
154
+ }, z.core.$strip>;
155
+ type FishAudioTranscriptionModelOptions = z.infer<typeof fishAudioTranscriptionModelOptionsSchema>;
156
+
157
+ declare const VERSION: string;
158
+
159
+ export { type FishAudioProvider, type FishAudioProviderSettings, FishAudioSpeechModel, type FishAudioSpeechModelId, type FishAudioSpeechModelOptions, type FishAudioSpeechVoiceId, FishAudioTranscriptionModel, type FishAudioTranscriptionModelId, type FishAudioTranscriptionModelOptions, VERSION, createFishAudio, fishAudio };