utilitas 1999.1.46 → 1999.1.48

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/alan.mjs CHANGED
@@ -44,13 +44,14 @@ const _NEED = [
44
44
 
45
45
  const [
46
46
  png, jpeg, mov, mpeg, mp4, mpg, avi, wmv, mpegps, flv, gif, webp, pdf, aac,
47
- flac, mp3, m4a, mpga, opus, pcm, wav, webm, tgpp, pcm16, ogg,
47
+ flac, mp3, mpega, m4a, mpga, opus, pcm, wav, webm, tgpp, pcm16, ogg,
48
48
  ] = [
49
49
  'image/png', 'image/jpeg', 'video/mov', 'video/mpeg', 'video/mp4',
50
50
  'video/mpg', 'video/avi', 'video/wmv', 'video/mpegps', 'video/x-flv',
51
51
  'image/gif', 'image/webp', 'application/pdf', 'audio/aac', 'audio/flac',
52
- 'audio/mp3', 'audio/m4a', 'audio/mpga', 'audio/opus', 'audio/pcm',
53
- 'audio/wav', 'audio/webm', 'video/3gpp', 'audio/x-wav', 'audio/ogg',
52
+ 'audio/mp3', 'audio/mpeg', 'audio/m4a', 'audio/mpga', 'audio/opus',
53
+ 'audio/pcm', 'audio/wav', 'audio/webm', 'video/3gpp', 'audio/x-wav',
54
+ 'audio/ogg',
54
55
  ];
55
56
 
56
57
  const [
@@ -124,7 +125,7 @@ const GEMINI_RULES = {
124
125
  maxImageSize: Infinity, maxUrlSize: gb(2), maxVideoLength: minute(45),
125
126
  maxVideoPerPrompt: 10, vision: true, supportedMimeTypes: [
126
127
  png, jpeg, mov, mpeg, mp4, mpg, avi, wmv, mpegps, flv, pdf, aac,
127
- flac, mp3, m4a, mpga, opus, pcm, wav, webm, tgpp,
128
+ flac, mp3, mpega, m4a, mpga, opus, pcm, wav, webm, tgpp,
128
129
  ], defaultProvider: GEMINI,
129
130
  };
130
131
 
@@ -1565,6 +1566,12 @@ export {
1565
1566
  listGptFineTuningEvents,
1566
1567
  listGptFineTuningJobs,
1567
1568
  listOpenAIModels,
1569
+ m4a,
1570
+ mp3,
1571
+ mp4,
1572
+ mpeg,
1573
+ mpega,
1574
+ mpga,
1568
1575
  ogg,
1569
1576
  prompt,
1570
1577
  promptAnthropic,
@@ -1577,5 +1584,6 @@ export {
1577
1584
  trimPrompt,
1578
1585
  uploadFile,
1579
1586
  uploadFileForFineTuning,
1580
- wav
1587
+ wav,
1588
+ webm,
1581
1589
  };
package/lib/bot.mjs CHANGED
@@ -7,10 +7,13 @@ import {
7
7
  throwError, timeout, trim, which,
8
8
  } from './utilitas.mjs';
9
9
 
10
+ import {
11
+ jpeg, ogg, wav, mp3, mpega, mp4, mpeg, mpga, m4a, webm,
12
+ } from './alan.mjs';
13
+
10
14
  import { readdirSync } from 'fs';
11
15
  import { parseArgs as _parseArgs } from 'node:util';
12
16
  import { basename, join } from 'path';
13
- import { jpeg, ogg, wav } from './alan.mjs';
14
17
  import { isPrimary, on, report } from './callosum.mjs';
15
18
  import { cleanSql, encodeVector, MYSQL, POSTGRESQL } from './dbio.mjs';
16
19
  import { convertAudioTo16kNanoPcmWave } from './media.mjs';
@@ -511,8 +514,10 @@ const subconscious = [{
511
514
  && (ctx.chatType = MENTION);
512
515
  (((ctx.txt || ctx.m.voice || ctx.m.poll || ctx.m.data || ctx.m.document
513
516
  || ctx.m.photo || ctx.m.sticker || ctx.m.video_note || ctx.m.video
514
- || ctx.m.location || ctx.m.venue || ctx.m.contact) && ctx.messageId)
515
- || (ctx.m.new_chat_member || ctx.m.left_chat_member)) && await next();
517
+ || ctx.m.audio || ctx.m.location || ctx.m.venue || ctx.m.contact
518
+ ) && ctx.messageId)
519
+ || (ctx.m.new_chat_member || ctx.m.left_chat_member))
520
+ && await next();
516
521
  await sessionSet(ctx.chatId);
517
522
  },
518
523
  }, {
@@ -647,15 +652,23 @@ const subconscious = [{
647
652
  },
648
653
  }, {
649
654
  run: true, priority: -8910, name: 'speech-to-text', func: async (ctx, next) => {
650
- if (ctx._.speech?.stt && ctx.m.voice?.mime_type === ogg) {
655
+ const audio = ctx.m.voice || ctx.m.audio;
656
+ if (ctx._.speech?.stt && audio) {
651
657
  await ctx.ok(EMOJI_SPEECH);
652
658
  try {
653
- const url = await getFileUrl(ctx.m.voice.file_id);
654
- const file = await getFile(ctx.m.voice.file_id, BUFFER_ENCODE);
659
+ const url = await getFileUrl(audio.file_id);
660
+ let file = await getFile(audio.file_id, BUFFER_ENCODE);
655
661
  const analyze = async () => {
656
- const resp = await ignoreErrFunc(
657
- async () => await ctx._.speech?.stt(file), logOptions
658
- ) || ' ';
662
+ const resp = await ignoreErrFunc(async () => {
663
+ [
664
+ mp3, mpega, mp4, mpeg, mpga, m4a, wav, webm, ogg
665
+ ].includes(audio.mime_type) || (
666
+ file = await convertAudioTo16kNanoPcmWave(
667
+ file, { input: BUFFER, expected: BUFFER }
668
+ )
669
+ );
670
+ return await ctx._.speech?.stt(file);
671
+ }, logOptions) || ' ';
659
672
  log(`STT: '${resp}'`);
660
673
  ctx.collect(resp);
661
674
  };
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.46",
4
+ "version": "1999.1.48",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
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.46",
4
+ "version": "1999.1.48",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",