-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio.ts
53 lines (47 loc) · 1.26 KB
/
audio.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Handler, Context, Callback } from "aws-lambda";
import VoiceData from "./src/model/voiceData";
import AudioHandler from "./src/audioHandler";
const CHATGPTPLUGINAUTH = process.env.CHATGPTPLUGINAUTH!;
const transcribe: Handler = async (
event: any,
context: Context,
callback: Callback,
) => {
try {
//console.log("event", event);
//const body = JSON.parse(event.body);
console.log("Audio request:", event);
if (
event &&
event.auth &&
event.audio &&
event.id &&
event.auth === CHATGPTPLUGINAUTH
) {
const audio = event.audio;
console.log(
"Audio data:",
audio.file_name,
audio.duration,
audio.file_size,
audio.mime_type,
);
const audioData = <VoiceData>{
mime_type: audio.mime_type,
file_id: audio.file_id,
file_size: audio.file_size,
};
const audioHandler = new AudioHandler(audioData);
await audioHandler.copyAudioToS3(event.id, audio.file_name);
await sleep(1000);
}
return 200;
} catch (error) {
console.error("catch", (<any>error).toString());
return 200;
}
};
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export { transcribe };