utilitas 1999.1.30 → 1999.1.32

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/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1999.1.30",
4
+ "version": "1999.1.32",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/speech.mjs CHANGED
@@ -26,11 +26,10 @@ const WHISPER_DEFAULT_MODEL = 'base';
26
26
  const errorMessage = 'Invalid audio data.';
27
27
  const [BUFFER, STREAM, BASE64, FILE, clients, languageCode, audioEncoding, suffix, SPEAKER, cleanup]
28
28
  = ['BUFFER', 'STREAM', 'BASE64', 'FILE', {}, 'en-US', 'OGG_OPUS', 'ogg', 'SPEAKER', true];
29
-
30
- // https://platform.openai.com/account/limits
31
- const [TTS_1, TTS_1_HD] = ['tts-1', 'tts-1-hd']; // [7500 RPM, 7500 RPM]
32
- const OPENAI_TTS_MAX_LENGTH = 4096;
33
- const defaultOpenAITtsModel = TTS_1;
29
+ const [GPT_4O_MIMI_TTS, GPT_4O_TRANSCRIBE, OPENAI_TTS_MAX_LENGTH]
30
+ = ['gpt-4o-mini-tts', 'gpt-4o-transcribe', 4096];
31
+ const [defaultOpenAITtsModel, defaultOpenAISttModel]
32
+ = [GPT_4O_MIMI_TTS, GPT_4O_TRANSCRIBE];
34
33
 
35
34
  const WHISPER_MODELS = [
36
35
  // npx whisper-node download tiny.en
@@ -147,12 +146,13 @@ const checkWhisper = async (options) => {
147
146
  };
148
147
 
149
148
  const ttsOpenAI = async (input, options) => {
150
- assert(clients.tts, 'Text-to-Speech API has not been initialized.', 500);
149
+ assert(clients.tts, 'OpenAI TTS API has not been initialized.', 500);
151
150
  assert(input, 'Text is required.', 400);
152
151
  assert(input.length <= OPENAI_TTS_MAX_LENGTH, 'Text is too long.', 400);
153
152
  // https://platform.openai.com/docs/api-reference/audio/createSpeech
154
153
  const content = await clients.tts.create({
155
154
  model: defaultOpenAITtsModel, voice: DEFAULT_MODELS[OPENAI_VOICE],
155
+ instructions: 'Speak in a friendly and sweet tone.',
156
156
  response_format: 'opus', input, ...options?.params || {},
157
157
  });
158
158
  const buffer = Buffer.from(await content.arrayBuffer());
@@ -160,7 +160,7 @@ const ttsOpenAI = async (input, options) => {
160
160
  };
161
161
 
162
162
  const ttsGoogle = async (text, options) => {
163
- assert(clients.tts, 'Text-to-Speech API has not been initialized.', 500);
163
+ assert(clients.tts, 'Google TTS API has not been initialized.', 500);
164
164
  assert(text, 'Text is required.', 400);
165
165
  const [response] = await clients.tts.synthesizeSpeech({
166
166
  input: { text, ...options?.input || {} },
@@ -197,7 +197,7 @@ const ttsBrowser = async (text) => {
197
197
  };
198
198
 
199
199
  const sttOpenAI = async (audio, options) => {
200
- assert(clients.stt, 'Speech-to-Text API has not been initialized.', 500);
200
+ assert(clients.stt, 'OpenAI STT API has not been initialized.', 500);
201
201
  const input = ensureString(options?.input, { case: 'UP' });
202
202
  const { content, cleanup } = await convert(audio, {
203
203
  input: options?.input, ...options || {}, expected: STREAM, errorMessage,
@@ -205,7 +205,7 @@ const sttOpenAI = async (audio, options) => {
205
205
  withCleanupFunc: true,
206
206
  });
207
207
  const result = await clients.stt.create({
208
- file: await clients.toFile(content), model: 'whisper-1',
208
+ file: await clients.toFile(content), model: defaultOpenAISttModel,
209
209
  response_format: 'text', ...options?.params || {},
210
210
  });
211
211
  await cleanup();
@@ -213,7 +213,7 @@ const sttOpenAI = async (audio, options) => {
213
213
  };
214
214
 
215
215
  const sttGoogle = async (audio, options) => {
216
- assert(clients.stt, 'Speech-to-Text API has not been initialized.', 500);
216
+ assert(clients.stt, 'Google STT API has not been initialized.', 500);
217
217
  const content = await convert(audio, {
218
218
  input: options?.input, expected: BASE64, errorMessage,
219
219
  });
package/lib/utilitas.mjs CHANGED
@@ -552,8 +552,8 @@ const renderCode = (code, options) => {
552
552
  x => `${String(i++).padStart(bits, '0')} ${s} ${ensureString(x).replace('```', '\\`\\`\\`')}`
553
553
  );
554
554
  const output = (
555
- options?.md ? `\`\`\`${options.md === true ? '' : options.md}\n` : ''
556
- ) + (options?.asArray ? resp : resp.join('\n')) + (options.md ? '\n```' : '');
555
+ options?.md ? `\`\`\`${options?.md === true ? '' : options?.md}\n` : ''
556
+ ) + (options?.asArray ? resp : resp.join('\n')) + (options?.md ? '\n```' : '');
557
557
  options?.log && console.log(output);
558
558
  return output;
559
559
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1999.1.30",
4
+ "version": "1999.1.32",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",