Skip to content

Commit 3db16a5

Browse files
committed
chore: simplify
1 parent 8e05c74 commit 3db16a5

8 files changed

Lines changed: 1 addition & 173 deletions

File tree

gatsby-node.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/images/example.png

-3.14 KB
Binary file not shown.

src/images/gatsby-icon.png

-20.7 KB
Binary file not shown.

src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FileUpload } from '../components/FileUpload';
55
import { LanguageSelector } from '../components/LanguageSelector';
66
import { TranslationResult } from '../components/TranslationResult';
77
import { transcribeAudio } from '../services/llmService';
8-
import { translateText, formatTextAsSubtitles } from '../services/translateService';
8+
import { translateText } from '../services/translateService';
99

1010
const languageOptions = [
1111
{ code: 'ar', name: 'Arabic (العربية)' },

src/pages/using-ssr.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/services/llmService.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
import { transcribeAudioWithOllama } from './localOllamaService';
22

3-
const formatTime = (seconds: number, type: 'srt' | 'vtt'): string => {
4-
const h = Math.floor(seconds / 3600);
5-
const m = Math.floor((seconds % 3600) / 60);
6-
const s = Math.floor(seconds % 60);
7-
const ms = Math.floor((seconds % 1) * 1000);
8-
9-
const hDisplay = h.toString().padStart(2, '0');
10-
const mDisplay = m.toString().padStart(2, '0');
11-
const sDisplay = s.toString().padStart(2, '0');
12-
const msDisplay = ms.toString().padStart(3, '0');
13-
14-
if (type === 'srt') {
15-
return `${hDisplay}:${mDisplay}:${sDisplay},${msDisplay}`;
16-
}
17-
return `${hDisplay}:${mDisplay}:${sDisplay}.${msDisplay}`;
18-
};
19-
20-
const segmentsToSRT = (segments: any[]): string => {
21-
return segments.map((seg, i) => {
22-
return `${i + 1}\n${formatTime(seg.start, 'srt')} --> ${formatTime(seg.end, 'srt')}\n${seg.text.trim()}\n`;
23-
}).join('\n');
24-
};
25-
26-
const segmentsToVTT = (segments: any[]): string => {
27-
return 'WEBVTT\n\n' + segments.map((seg) => {
28-
return `${formatTime(seg.start, 'vtt')} --> ${formatTime(seg.end, 'vtt')}\n${seg.text.trim()}\n`;
29-
}).join('\n');
30-
};
31-
323
export const transcribeAudio = async (
334
file: File,
345
sourceLanguage: string,

src/services/translateService.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -111,47 +111,3 @@ export const translateText = async (
111111
const data = await response.json();
112112
return data.choices?.[0]?.message?.content || '';
113113
};
114-
115-
/**
116-
* If transcription returns plain text but SRT was requested,
117-
* this helper uses the LLM to format the plain text into an SRT structure.
118-
*/
119-
export const formatTextAsSubtitles = async (
120-
text: string,
121-
responseFormat: string = 'srt',
122-
model: string = 'chat'
123-
): Promise<string> => {
124-
if (responseFormat !== 'srt' && responseFormat !== 'vtt') return text;
125-
if (text.includes('-->')) return text; // Already has timings
126-
127-
const apiKey = process.env.GATSBY_LITELLM_API_KEY;
128-
if (!apiKey) return text;
129-
130-
const response = await fetch('/v1/chat/completions', {
131-
method: 'POST',
132-
headers: {
133-
'Content-Type': 'application/json',
134-
'Authorization': `Bearer ${apiKey}`
135-
},
136-
body: JSON.stringify({
137-
model: model,
138-
messages: [
139-
{
140-
role: 'system',
141-
content: `You are a professional subtitle editor.
142-
Convert the following plain text transcript into a valid ${responseFormat.toUpperCase()} file.
143-
Since you don't have exact timings, create reasonable estimated timestamps or a single long segment.
144-
Provide ONLY the ${responseFormat.toUpperCase()} content without any commentary.`
145-
},
146-
{
147-
role: 'user',
148-
content: text
149-
}
150-
]
151-
}),
152-
});
153-
154-
if (!response.ok) return text;
155-
const data = await response.json();
156-
return data.choices?.[0]?.message?.content || text;
157-
};

src/templates/using-dsg.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)