Skip to content

Commit 2b1a54d

Browse files
committed
Use audio transcription API
1 parent d7a4b51 commit 2b1a54d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

apps/mobile/src/features/chat/hooks/useVoiceRecording.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Audio } from "expo-av";
22
import { File } from "expo-file-system";
33
import { useCallback, useRef, useState } from "react";
4+
import { useAuthStore } from "../../auth";
45

56
type RecordingStatus = "idle" | "recording" | "transcribing" | "error";
67

@@ -74,29 +75,36 @@ export function useVoiceRecording(): UseVoiceRecordingReturn {
7475
return null;
7576
}
7677

77-
const openaiApiKey = process.env.EXPO_PUBLIC_OPENAI_API_KEY;
78-
if (!openaiApiKey) {
79-
setError("EXPO_PUBLIC_OPENAI_API_KEY not set");
78+
const {
79+
oauthAccessToken,
80+
cloudRegion,
81+
projectId,
82+
getCloudUrlFromRegion,
83+
} = useAuthStore.getState();
84+
85+
if (!oauthAccessToken || !cloudRegion || !projectId) {
86+
setError("Not authenticated");
8087
setStatus("error");
8188
return null;
8289
}
8390

91+
const cloudUrl = getCloudUrlFromRegion(cloudRegion);
92+
8493
// Create form data with the recording file
8594
const formData = new FormData();
8695
formData.append("file", {
8796
uri,
88-
type: "audio/m4a",
97+
type: "audio/mp4",
8998
name: "recording.m4a",
9099
} as unknown as Blob);
91-
formData.append("model", "gpt-4o-transcribe");
92100

93-
// Call OpenAI transcription API
101+
// Call PostHog LLM Gateway transcription API
94102
const response = await fetch(
95-
"https://api.openai.com/v1/audio/transcriptions",
103+
`${cloudUrl}/api/projects/${projectId}/llm_gateway/v1/audio/transcriptions`,
96104
{
97105
method: "POST",
98106
headers: {
99-
Authorization: `Bearer ${openaiApiKey}`,
107+
Authorization: `Bearer ${oauthAccessToken}`,
100108
},
101109
body: formData,
102110
},

0 commit comments

Comments
 (0)