| 77 | |
| 78 | // Construct a MicrophoneIterator and start the audio stream. |
| 79 | static async create(microphoneConfig: MicrophoneConfig = {}) { |
| 80 | if (!env().get('IS_BROWSER')) { |
| 81 | throw new Error( |
| 82 | 'microphone API is only supported in browser environment.'); |
| 83 | } |
| 84 | |
| 85 | const microphoneIterator = new MicrophoneIterator(microphoneConfig); |
| 86 | |
| 87 | // Call async function start() to initialize the audio stream. |
| 88 | await microphoneIterator.start(); |
| 89 | |
| 90 | return microphoneIterator; |
| 91 | } |
| 92 | |
| 93 | // Start the audio stream and FFT. |
| 94 | async start(): Promise<void> { |