-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
telegram bot can now undertand voice messages
- Loading branch information
Showing
10 changed files
with
115 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
piplelineTransformer, | ||
//@ts-ignore | ||
} from "../../../utils/pipleline.js"; | ||
import { WaveFile } from "wavefile"; | ||
|
||
function _convert(audio: Buffer) { | ||
const wav = new WaveFile(audio); | ||
wav.toBitDepth("32f"); | ||
wav.toSampleRate(16000); | ||
let audioData = wav.getSamples(); | ||
if (Array.isArray(audioData)) { | ||
console.log( | ||
"Multiple channels detected. Selecting the first channel only." | ||
); | ||
audioData = audioData[0]; | ||
} | ||
return audioData; | ||
} | ||
|
||
export const convertTextToAudio = async (audioData: Buffer) => { | ||
const pipeline = await piplelineTransformer(); | ||
const transcriber = await pipeline( | ||
"automatic-speech-recognition", | ||
process.env.WHISPER_MODEL || "distil-whisper/distil-medium.en" | ||
); | ||
|
||
const audio = _convert(Buffer.from(audioData)); | ||
let output = (await transcriber(audio, { | ||
chunk_length_s: 30, | ||
})) as { | ||
text: string; | ||
}; | ||
|
||
return output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters