Skip to content

Commit a98c3bf

Browse files
authored
chore: consume types from microphone-stream package (#18)
1 parent db53180 commit a98c3bf

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

packages/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@aws-sdk/util-create-request": "3.4.1",
1313
"@aws-sdk/util-format-url": "3.4.1",
1414
"@reach/router": "1.3.4",
15-
"microphone-stream": "5.1.0",
15+
"microphone-stream": "5.2.0",
1616
"react": "17.0.1",
1717
"react-bootstrap": "1.4.0",
1818
"react-dom": "17.0.1"

packages/frontend/src/content/RecordAudioButton.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { useState } from "react";
22
import { Button, Alert } from "react-bootstrap";
33
import { MicFill, MicMute } from "react-bootstrap-icons";
44

5-
// @ts-ignore https://github.com/saebekassebil/microphone-stream/issues/39
6-
import * as MicrophoneStream from "microphone-stream";
5+
import MicrophoneStream from "microphone-stream";
76

87
import { pcmEncode } from "../libs/audioUtils";
98
import { getStreamTranscriptionResponse } from "../libs/getStreamTranscriptionResponse";
@@ -14,19 +13,19 @@ const RecordAudioButton = (props: {
1413
setNoteContent: Function;
1514
}) => {
1615
const { isRecording, setIsRecording, setNoteContent } = props;
17-
const [micStream, setMicStream] = useState<any>();
16+
const [micStream, setMicStream] = useState<MicrophoneStream | undefined>();
1817
const [errorMsg, setErrorMsg] = useState("");
1918

2019
const toggleTrascription = async () => {
2120
if (isRecording) {
2221
setIsRecording(false);
2322
if (micStream) {
2423
micStream.stop();
25-
setMicStream(null);
24+
setMicStream(undefined);
2625
}
2726
} else {
2827
setIsRecording(true);
29-
let mic: any;
28+
let mic;
3029
try {
3130
const audio = await navigator.mediaDevices.getUserMedia({
3231
audio: true,
@@ -42,21 +41,22 @@ const RecordAudioButton = (props: {
4241
} finally {
4342
if (mic) {
4443
mic.stop();
45-
setMicStream(null);
44+
setMicStream(undefined);
4645
}
4746
setIsRecording(false);
4847
}
4948
}
5049
};
5150

52-
const streamAudioToWebSocket = async (micStream: any) => {
53-
const pcmEncodeChunk = (audioChunk: any) => {
51+
const streamAudioToWebSocket = async (micStream: MicrophoneStream) => {
52+
const pcmEncodeChunk = (audioChunk: Buffer) => {
5453
const raw = MicrophoneStream.toRaw(audioChunk);
5554
if (raw == null) return;
5655
return Buffer.from(pcmEncode(raw));
5756
};
5857

5958
const transcribeInput = async function* () {
59+
// @ts-ignore Type 'MicrophoneStream' is not an array type or a string type.
6060
for await (const chunk of micStream) {
6161
yield { AudioEvent: { AudioChunk: pcmEncodeChunk(chunk) } };
6262
}
@@ -81,7 +81,9 @@ const RecordAudioButton = (props: {
8181

8282
const transcriptionToRemove = partialTranscription;
8383
// fix encoding for accented characters.
84-
const transcription = decodeURIComponent(escape(Transcript || ""));
84+
const transcription = decodeURIComponent(
85+
escape(Transcript || "")
86+
);
8587

8688
setNoteContent(
8789
(noteContent: any) =>

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ __metadata:
767767
"@types/react": 17.0.0
768768
"@types/react-dom": 17.0.0
769769
local-web-server: ^4.2.1
770-
microphone-stream: 5.1.0
770+
microphone-stream: 5.2.0
771771
react: 17.0.1
772772
react-bootstrap: 1.4.0
773773
react-bootstrap-icons: 1.3.0
@@ -15105,13 +15105,13 @@ fsevents@^1.2.7:
1510515105
languageName: node
1510615106
linkType: hard
1510715107

15108-
"microphone-stream@npm:5.1.0":
15109-
version: 5.1.0
15110-
resolution: "microphone-stream@npm:5.1.0"
15108+
"microphone-stream@npm:5.2.0":
15109+
version: 5.2.0
15110+
resolution: "microphone-stream@npm:5.2.0"
1511115111
dependencies:
1511215112
buffer-from: ^1.1.1
1511315113
readable-stream: ^3.6.0
15114-
checksum: b64869f02fba7e00025d32fcf6bbc2b7ef6f0e52c63e98e2f9a4cf108e9bc2b72c193092e056b1e39fb068aab757cf3a3f5155a74dfedbc8702825d344ca80c8
15114+
checksum: fc28b6150bac409b6c124411f370b3962acac7c68fa6da04e85795f1d8fb40977de583db4f856d6ba658f692d30a9f5931a308d3fc52cf6d3c9814738815c6f7
1511515115
languageName: node
1511615116
linkType: hard
1511715117

0 commit comments

Comments
 (0)