BREAKING CHANGE(vercel-ai-sdk): migrate to Vercel AI SDK v6 and introduce provider registry (getModel) returning LanguageModelV3
This commit is contained in:
24
ts_audio/index.ts
Normal file
24
ts_audio/index.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
export interface IOpenAiTtsOptions {
|
||||
apiKey: string;
|
||||
text: string;
|
||||
voice?: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer';
|
||||
model?: 'tts-1' | 'tts-1-hd';
|
||||
responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac';
|
||||
speed?: number;
|
||||
}
|
||||
|
||||
export async function textToSpeech(options: IOpenAiTtsOptions): Promise<NodeJS.ReadableStream> {
|
||||
const client = new plugins.OpenAI({ apiKey: options.apiKey });
|
||||
const result = await client.audio.speech.create({
|
||||
model: options.model ?? 'tts-1',
|
||||
voice: options.voice ?? 'alloy',
|
||||
input: options.text,
|
||||
response_format: options.responseFormat ?? 'mp3',
|
||||
speed: options.speed ?? 1,
|
||||
});
|
||||
const stream = result.body;
|
||||
return Readable.fromWeb(stream as any);
|
||||
}
|
||||
2
ts_audio/plugins.ts
Normal file
2
ts_audio/plugins.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import OpenAI from 'openai';
|
||||
export { OpenAI };
|
||||
Reference in New Issue
Block a user