|
1 | 1 | import { Audio } from "expo-av"; |
2 | 2 | import { File } from "expo-file-system"; |
3 | 3 | import { useCallback, useRef, useState } from "react"; |
| 4 | +import { useAuthStore } from "../../auth"; |
4 | 5 |
|
5 | 6 | type RecordingStatus = "idle" | "recording" | "transcribing" | "error"; |
6 | 7 |
|
@@ -74,29 +75,36 @@ export function useVoiceRecording(): UseVoiceRecordingReturn { |
74 | 75 | return null; |
75 | 76 | } |
76 | 77 |
|
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"); |
80 | 87 | setStatus("error"); |
81 | 88 | return null; |
82 | 89 | } |
83 | 90 |
|
| 91 | + const cloudUrl = getCloudUrlFromRegion(cloudRegion); |
| 92 | + |
84 | 93 | // Create form data with the recording file |
85 | 94 | const formData = new FormData(); |
86 | 95 | formData.append("file", { |
87 | 96 | uri, |
88 | | - type: "audio/m4a", |
| 97 | + type: "audio/mp4", |
89 | 98 | name: "recording.m4a", |
90 | 99 | } as unknown as Blob); |
91 | | - formData.append("model", "gpt-4o-transcribe"); |
92 | 100 |
|
93 | | - // Call OpenAI transcription API |
| 101 | + // Call PostHog LLM Gateway transcription API |
94 | 102 | const response = await fetch( |
95 | | - "https://api.openai.com/v1/audio/transcriptions", |
| 103 | + `${cloudUrl}/api/projects/${projectId}/llm_gateway/v1/audio/transcriptions`, |
96 | 104 | { |
97 | 105 | method: "POST", |
98 | 106 | headers: { |
99 | | - Authorization: `Bearer ${openaiApiKey}`, |
| 107 | + Authorization: `Bearer ${oauthAccessToken}`, |
100 | 108 | }, |
101 | 109 | body: formData, |
102 | 110 | }, |
|
0 commit comments