@olares/lares-mobile 0.15.38 → 0.15.39
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/package.json +2 -2
- package/src/chat/playback.js +29 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olares/lares-mobile",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.39",
|
|
4
4
|
"description": "Lares chat component for LarePass",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"vue": "^3.2.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@olares/lares-core": "0.15.
|
|
31
|
+
"@olares/lares-core": "0.15.39",
|
|
32
32
|
"markdown-it": "^14.3.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/chat/playback.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { primePlaybackContext } from "@olares/lares-core/voice/pcm-player";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 16-bit silence at the playback clock. iOS keeps one hardware rate; the old
|
|
5
|
+
* 8 kHz unlock left the iPhone speaker resampling the readout into a buzz.
|
|
6
|
+
*/
|
|
7
|
+
function unlockClip(sampleRate) {
|
|
8
|
+
const rate = Number.isInteger(sampleRate) && sampleRate >= 8000 && sampleRate <= 192000 ? sampleRate : 48000;
|
|
9
|
+
const dataBytes = 128 * 2;
|
|
10
|
+
const bytes = new Uint8Array(44 + dataBytes);
|
|
11
|
+
const view = new DataView(bytes.buffer);
|
|
12
|
+
const text = (offset, value) => { for (let i = 0; i < value.length; i += 1) view.setUint8(offset + i, value.charCodeAt(i)); };
|
|
13
|
+
text(0, "RIFF");
|
|
14
|
+
view.setUint32(4, 36 + dataBytes, true);
|
|
15
|
+
text(8, "WAVE");
|
|
16
|
+
text(12, "fmt ");
|
|
17
|
+
view.setUint32(16, 16, true);
|
|
18
|
+
view.setUint16(20, 1, true);
|
|
19
|
+
view.setUint16(22, 1, true);
|
|
20
|
+
view.setUint32(24, rate, true);
|
|
21
|
+
view.setUint32(28, rate * 2, true);
|
|
22
|
+
view.setUint16(32, 2, true);
|
|
23
|
+
view.setUint16(34, 16, true);
|
|
24
|
+
text(36, "data");
|
|
25
|
+
view.setUint32(40, dataBytes, true);
|
|
26
|
+
let binary = "";
|
|
27
|
+
for (let i = 0; i < bytes.length; i += 1) binary += String.fromCharCode(bytes[i]);
|
|
28
|
+
return `data:audio/wav;base64,${btoa(binary)}`;
|
|
29
|
+
}
|
|
4
30
|
|
|
5
31
|
/**
|
|
6
32
|
* One element, unlocked inside the gesture that asks the question (a voice
|
|
@@ -22,9 +48,9 @@ export function createAnswerPlayer() {
|
|
|
22
48
|
};
|
|
23
49
|
return {
|
|
24
50
|
unlock() {
|
|
25
|
-
primePlaybackContext();
|
|
51
|
+
const context = primePlaybackContext();
|
|
26
52
|
if (!audio || !audio.paused) return;
|
|
27
|
-
audio.src =
|
|
53
|
+
audio.src = unlockClip(context?.sampleRate);
|
|
28
54
|
void audio.play().catch(() => {});
|
|
29
55
|
},
|
|
30
56
|
/** Resolves when the clip ends (true), or is stopped or fails (false). */
|