Skip to content

Commit

Permalink
Merge pull request #12 from Rei-x/fix-audio-stream-error
Browse files Browse the repository at this point in the history
Fix opus error
  • Loading branch information
Rei-x committed Sep 26, 2021
2 parents 2330ee7 + 9c38558 commit b944e85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/bot/discordSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export default class DiscordSR {
});
const bufferData: Uint8Array[] = [];

audioStream.on("error", (error) => {
this.client.emit("audioStreamError", error);
});

audioStream.on("data", (data) => {
bufferData.push(data);
});
Expand Down
8 changes: 8 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ export declare function voiceJoin(connection: VoiceConnection): void;
* @event
*/
export declare function speech(voiceMessage: VoiceMessage): void;

/**
* Emitted when error occurs during processing audio stream. Usually when someone tries to talk using web version of discord. See https://github.com/discordjs/opus/issues/49
* @asMemberOf DiscordSR
* @param error
* @event
*/
export declare function audioStreamError(error: Error): void;
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export {
default as DiscordSR,
DiscordSROptions,
SpeechRecognition as speechRecognition,
SpeechRecognitionOptions,
DiscordSROptions,
} from "./bot/discordSR";
export { speech, voiceJoin } from "./events";
export { default as VoiceMessage } from "./bot/voiceMessage";
export { audioStreamError, speech, voiceJoin } from "./events";
export {
resolveSpeechWithGoogleSpeechV2,
GoogleSpeechV2Options,
resolveSpeechWithGoogleSpeechV2,
} from "./speechRecognition/googleV2";
export {
resolveSpeechWithWITAI,
WitaiOptions as WITAIOptions,
} from "./speechRecognition/witAI";
export { wavUrlToBuffer, getDurationFromMonoBuffer } from "./utils/audio";
export { getDurationFromMonoBuffer, wavUrlToBuffer } from "./utils/audio";

0 comments on commit b944e85

Please sign in to comment.