import { Hono } from "npm:hono@3";
import { html } from "npm:hono@3/html";
import { cors } from 'npm:hono/cors';
import { OpenAI } from "npm:openai";
const app = new Hono();
const openai = new OpenAI(Deno.env.get("OPENAI_API_KEY_VOICE"));
class TranscriptionService {
async transcribeAudio(audioFile) {
try {
const transcription = await openai.audio.transcriptions.create({
file: audioFile,
model: "whisper-1",
response_format: "text",
});
return transcription;
} catch (error) {
console.error('OpenAI API error:', error);
throw error;
}
}
}
export const transcriptionService = new TranscriptionService();
app.use('*', cors({
origin: '*',
allowMethods: ['GET', 'POST'],
allowHeaders: ['Content-Type'],
}));
app.get("/", async (c) => {
const languages = [
"Afrikaans", "Arabic", "Armenian", "Azerbaijani", "Belarusian", "Bosnian", "Bulgarian", "Catalan", "Chinese", "Croatian", "Czech", "Danish", "Dutch", "English", "Estonian", "Finnish", "French", "Galician", "German", "Greek", "Hebrew", "Hindi", "Hungari
];
const voices = [
"alloy",
"echo",
"fable",
"onyx",
"nova",
"shimmer"
];
const resHtml = html`
<!DOCTYPE html>
<html>
<head>
<title>Translator</title>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
html {
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
@media (max-width: 640px) {
.container {
max-width: 100%;
padding: 1rem;
}
button {
font-size: 1.5rem;
padding: 1rem 2rem;
}
select {
font-size: 1.2rem;
padding: 0.8rem;
}
audio {
width: 100%;
}
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container mx-auto py-8 px-8" x-data="recordingData">
<h1 class="text-4xl font-bold mb-4">Translator</h1>
<div class="mb-4">
<h2 class="font-bold mb-2">Languages</h2>
<div class="grid grid-cols-2 gap-4" x-data="{
languages: [
'Afrikaans', 'Arabic', 'Armenian', 'Azerbaijani', 'Belarusian', 'Bosnian', 'Bulgarian', 'Catalan', 'Chinese', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Estonian', 'Finnish', 'French', 'Galician', 'German', 'Greek', 'Hebrew', 'Hind
]
}">
<div>
<select id="language1" name="language1" class="border border-gray-300 rounded px-4 py-2 mb-4 w-full">
<template x-for="lang in languages">