Skip to content

Commit

Permalink
feat: support non-english languages
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Dec 16, 2023
1 parent 0e2f2d9 commit a65b25c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/services/ai/deepgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { z } from 'zod';

const deepgram = createDeepgramClient(env.DEEPGRAM_API_KEY);

export const transcribeAudio = async ({ fileURL }: { fileURL: string }) => {
export const transcribeAudio = async ({
language = 'en',
url,
}: {
language?: string;
url: string;
}) => {
const { error, result } = await deepgram.listen.prerecorded.transcribeUrl(
{
url: fileURL,
url,
},
{
model: 'nova-2',
language,
model: language === 'en' ? 'nova-2' : 'base',
paragraphs: true,
smart_format: true,
},
Expand Down
9 changes: 6 additions & 3 deletions lib/services/ai/transcribe-episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ export const transcribeEpisode = async (id: Tables<'episode'>['id']) => {

const episodeQuery = await supabase
.from('episode')
.select('audio_url')
.select('audio_url, show(language)')
.eq('id', id)
.single();

if (episodeQuery.error) {
throw new DatabaseError(episodeQuery.error);
}

const fileURL = await getFinalRedirectURL(episodeQuery.data.audio_url);
const transcription = await transcribeAudio({ fileURL });
const url = await getFinalRedirectURL(episodeQuery.data.audio_url);
const transcription = await transcribeAudio({
language: episodeQuery.data.show?.language ?? undefined,
url,
});

const updateEpisodeContentQuery = await supabase
.from('episode_content')
Expand Down

0 comments on commit a65b25c

Please sign in to comment.