| 83 | |
| 84 | /** Maps a raw recognition error to a normalised code, or `null` to ignore it. */ |
| 85 | const mapErrorCode = (error: string): VoiceInputErrorCode | null => { |
| 86 | switch (error) { |
| 87 | case 'aborted': |
| 88 | return null; |
| 89 | case 'not-allowed': |
| 90 | case 'service-not-allowed': |
| 91 | return 'not-allowed'; |
| 92 | case 'network': |
| 93 | return 'network'; |
| 94 | case 'no-speech': |
| 95 | return 'no-speech'; |
| 96 | case 'audio-capture': |
| 97 | return 'audio-capture'; |
| 98 | case 'language-not-supported': |
| 99 | return 'language-not-supported'; |
| 100 | case 'phrases-not-supported': |
| 101 | return 'phrases-not-supported'; |
| 102 | default: |
| 103 | return 'unknown'; |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | /** Maps a getUserMedia rejection to a normalised error code. */ |
| 108 | const mapMediaError = (err: unknown): VoiceInputErrorCode => { |