@@ -2,8 +2,7 @@ import React, { useState } from "react";
22import { Button , Alert } from "react-bootstrap" ;
33import { 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
87import { pcmEncode } from "../libs/audioUtils" ;
98import { 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 ) =>
0 commit comments