Added initial codebase for open-audio
This commit is contained in:
parent
512c701060
commit
5e53a36c9e
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,3 +34,5 @@ yarn-error.log*
|
|||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
|
.env
|
2250
package-lock.json
generated
2250
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -9,15 +9,22 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@chakra-ui/icons": "^2.1.1",
|
||||||
|
"@chakra-ui/react": "^2.8.1",
|
||||||
|
"@emotion/react": "^11.11.1",
|
||||||
|
"@emotion/styled": "^11.11.0",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
|
"framer-motion": "^10.16.4",
|
||||||
|
"next": "14.0.1",
|
||||||
|
"openai": "^4.16.1",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18"
|
||||||
"next": "14.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.0.1",
|
"autoprefixer": "^10.0.1",
|
||||||
"postcss": "^8",
|
|
||||||
"tailwindcss": "^3.3.0",
|
|
||||||
"eslint": "^8",
|
"eslint": "^8",
|
||||||
"eslint-config-next": "14.0.1"
|
"eslint-config-next": "14.0.1",
|
||||||
|
"postcss": "^8",
|
||||||
|
"tailwindcss": "^3.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
public/favicon.png
Executable file
BIN
public/favicon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 283 B |
1
public/og-image.svg
Normal file
1
public/og-image.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 33 KiB |
@ -1,5 +1,13 @@
|
|||||||
import '@/styles/globals.css'
|
import '@/styles/globals.css'
|
||||||
|
import { ChakraProvider, extendTheme } from '@chakra-ui/react';
|
||||||
|
|
||||||
|
const theme = extendTheme({});
|
||||||
|
|
||||||
|
|
||||||
export default function App({ Component, pageProps }) {
|
export default function App({ Component, pageProps }) {
|
||||||
return <Component {...pageProps} />
|
return (
|
||||||
}
|
<ChakraProvider theme={theme}> {/* If using a custom theme */}
|
||||||
|
<Component {...pageProps} />
|
||||||
|
</ChakraProvider>
|
||||||
|
);
|
||||||
|
}
|
@ -3,7 +3,32 @@ import { Html, Head, Main, NextScript } from 'next/document'
|
|||||||
export default function Document() {
|
export default function Document() {
|
||||||
return (
|
return (
|
||||||
<Html lang="en">
|
<Html lang="en">
|
||||||
<Head />
|
<Head>
|
||||||
|
{/* Page Title */}
|
||||||
|
<title>Open-Audio TTS</title>
|
||||||
|
|
||||||
|
{/* Favicon */}
|
||||||
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon.png" />
|
||||||
|
|
||||||
|
{/* Meta Tags for SEO */}
|
||||||
|
<meta name="description" content="An OpenAI-powered Text-to-Speech tool." />
|
||||||
|
|
||||||
|
{/* Open Graph / Facebook */}
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://www.yourdomain.com/" />
|
||||||
|
<meta property="og:title" content="Open-Audio TTS" />
|
||||||
|
<meta property="og:description" content="An OpenAI-powered Text-to-Speech tool." />
|
||||||
|
<meta property="og:image" content="https://www.yourdomain.com/images/og-image.svg" />
|
||||||
|
|
||||||
|
{/* Twitter */}
|
||||||
|
<meta property="twitter:card" content="summary_large_image" />
|
||||||
|
<meta property="twitter:url" content="https://www.yourdomain.com/" />
|
||||||
|
<meta property="twitter:title" content="Open-Audio TTS" />
|
||||||
|
<meta property="twitter:description" content="An OpenAI-powered Text-to-Speech tool." />
|
||||||
|
<meta property="twitter:image" content="https://www.yourdomain.com/images/twitter-og-image.svg" />
|
||||||
|
|
||||||
|
{/* Add additional meta tags as needed */}
|
||||||
|
</Head>
|
||||||
<body>
|
<body>
|
||||||
<Main />
|
<Main />
|
||||||
<NextScript />
|
<NextScript />
|
||||||
|
@ -1,118 +1,294 @@
|
|||||||
import Image from 'next/image'
|
// pages/index.js
|
||||||
import { Inter } from 'next/font/google'
|
import {
|
||||||
|
Container,
|
||||||
|
Flex,
|
||||||
|
Heading,
|
||||||
|
FormControl,
|
||||||
|
FormLabel,
|
||||||
|
Input,
|
||||||
|
Textarea,
|
||||||
|
Select,
|
||||||
|
Button,
|
||||||
|
VStack,
|
||||||
|
HStack,
|
||||||
|
Slider,
|
||||||
|
SliderTrack,
|
||||||
|
SliderFilledTrack,
|
||||||
|
SliderThumb,
|
||||||
|
SliderMark,
|
||||||
|
Text,
|
||||||
|
useToast,
|
||||||
|
Spinner,
|
||||||
|
Grid,
|
||||||
|
Box,
|
||||||
|
Tooltip,
|
||||||
|
Switch,
|
||||||
|
FormHelperText
|
||||||
|
} from '@chakra-ui/react';
|
||||||
|
import OpenAI from "openai";
|
||||||
|
import { useState, useRef, useEffect } from 'react';
|
||||||
|
import { saveAs } from 'file-saver'; // You will need to install file-saver: npm install file-saver
|
||||||
|
|
||||||
const inter = Inter({ subsets: ['latin'] })
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
const [apiKeyInput, setApiKey] = useState('');
|
||||||
|
const [model, setModel] = useState('tts-1');
|
||||||
|
const [inputText, setInputText] = useState('');
|
||||||
|
const [voice, setVoice] = useState('alloy');
|
||||||
|
const [speed, setSpeed] = useState(1);
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
const [sliderValue, setSliderValue] = useState(1);
|
||||||
|
const [showTooltip, setShowTooltip] = useState(false);
|
||||||
|
const sliderRef = useRef(null);
|
||||||
|
const [audioUrl, setAudioUrl] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Clean up the URL object when the component is unmounted or audioUrl changes
|
||||||
|
return () => {
|
||||||
|
if (audioUrl) {
|
||||||
|
URL.revokeObjectURL(audioUrl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [audioUrl]);
|
||||||
|
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
|
const handleModelToggle = () => {
|
||||||
|
setModel(model === 'tts-1' ? 'tts-1-hd' : 'tts-1');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDownload = () => {
|
||||||
|
saveAs(audioUrl, 'speech.mp3'); // This will save the file as "speech.mp3"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Assuming `openai.audio.speech.create` returns a stream or binary data
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setIsSubmitting(true);
|
||||||
|
setAudioUrl(null);
|
||||||
|
try {
|
||||||
|
// Define the request headers
|
||||||
|
const headers = new Headers();
|
||||||
|
headers.append("Authorization", `Bearer ${apiKeyInput}`);
|
||||||
|
headers.append("Content-Type", "application/json");
|
||||||
|
|
||||||
|
// Define the request body
|
||||||
|
const body = JSON.stringify({
|
||||||
|
model: model,
|
||||||
|
input: inputText,
|
||||||
|
voice: voice,
|
||||||
|
speed: speed.toFixed(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Make the fetch request to the OpenAI API
|
||||||
|
const response = await fetch('https://api.openai.com/v1/audio/speech', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: headers,
|
||||||
|
body: body,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the response body as Blob
|
||||||
|
const blob = await response.blob();
|
||||||
|
|
||||||
|
// Create a URL for the Blob
|
||||||
|
const audioUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// Update your component's state or context
|
||||||
|
setAudioUrl(audioUrl);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
toast({
|
||||||
|
title: 'An error occurred',
|
||||||
|
description: error.message,
|
||||||
|
status: 'error',
|
||||||
|
duration: 5000,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleInputChange = (e) => {
|
||||||
|
if (e.target.value.length <= 4096) {
|
||||||
|
setInputText(e.target.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main
|
<Container bg={'gray.100'} maxW="container">
|
||||||
className={`flex min-h-screen flex-col items-center justify-between p-24 ${inter.className}`}
|
<Container centerContent p={4} maxW="container.md">
|
||||||
>
|
<Flex direction="column" align="center" justify="center" minH="100vh" w="full">
|
||||||
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
|
<Box
|
||||||
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
|
bg="white" // Assuming the card is white
|
||||||
Get started by editing
|
borderRadius="lg" // Rounded corners
|
||||||
<code className="font-mono font-bold">src/pages/index.js</code>
|
boxShadow="lg" // Shadow effect
|
||||||
</p>
|
p={6} // Padding inside the card
|
||||||
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
|
w="full" // Full width of the parent
|
||||||
<a
|
maxW="md" // Maximum width
|
||||||
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
|
|
||||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
>
|
||||||
By{' '}
|
<VStack spacing={6} as="form" onSubmit={handleSubmit} width="full" maxW="md">
|
||||||
<Image
|
<Box bg='black' w='100%' p={5} borderTopRadius="md" boxShadow="lg">
|
||||||
src="/vercel.svg"
|
<Heading textAlign="center" color="white">Open-Audio TTS</Heading>
|
||||||
alt="Vercel Logo"
|
<Text fontSize="xs" color="gray.100" textAlign="center" mt={2}>Powered by OpenAI TTS</Text>
|
||||||
className="dark:invert"
|
</Box>
|
||||||
width={100}
|
<Grid
|
||||||
height={24}
|
templateColumns={{ md: '4fr 1fr' }} // 80-20 ratio
|
||||||
priority
|
gap={4}
|
||||||
/>
|
width="full"
|
||||||
</a>
|
>
|
||||||
</div>
|
<FormControl isRequired>
|
||||||
</div>
|
<FormLabel htmlFor='api-key'>API Key</FormLabel>
|
||||||
|
<Input
|
||||||
|
id='api-key'
|
||||||
|
placeholder='Enter your OpenAI API key'
|
||||||
|
type='password'
|
||||||
|
value={apiKeyInput}
|
||||||
|
onChange={(e) => setApiKey(e.target.value)}
|
||||||
|
variant="outline"
|
||||||
|
borderColor="black"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700/10 after:dark:from-sky-900 after:dark:via-[#0141ff]/40 before:lg:h-[360px]">
|
<FormControl>
|
||||||
<Image
|
<VStack align="start" spacing={0}>
|
||||||
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
|
<FormLabel htmlFor='model'>
|
||||||
src="/next.svg"
|
Quality
|
||||||
alt="Next.js Logo"
|
</FormLabel>
|
||||||
width={180}
|
<HStack align="center" h='100%' mx='0' mt='2' >
|
||||||
height={37}
|
<Switch
|
||||||
priority
|
id='model'
|
||||||
/>
|
colorScheme="blackAlpha"
|
||||||
</div>
|
isChecked={model === 'tts-1-hd'}
|
||||||
|
onChange={handleModelToggle}
|
||||||
|
size="md" // Optional: if you want a larger switch
|
||||||
|
/>
|
||||||
|
<FormHelperText textAlign="center" mt={'-1'}>
|
||||||
|
{model === 'tts-1' ? 'High' : 'HD'}
|
||||||
|
</FormHelperText>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
|
</Grid>
|
||||||
<a
|
|
||||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
|
|
||||||
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<h2 className={`mb-3 text-2xl font-semibold`}>
|
|
||||||
Docs{' '}
|
|
||||||
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
|
|
||||||
->
|
|
||||||
</span>
|
|
||||||
</h2>
|
|
||||||
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
|
|
||||||
Find in-depth information about Next.js features and API.
|
|
||||||
</p>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a
|
<FormControl isRequired>
|
||||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
|
<FormLabel htmlFor='input-text'>Input Text</FormLabel>
|
||||||
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
|
<Textarea
|
||||||
target="_blank"
|
id='input-text'
|
||||||
rel="noopener noreferrer"
|
placeholder='Enter the text you want to convert to speech'
|
||||||
>
|
value={inputText}
|
||||||
<h2 className={`mb-3 text-2xl font-semibold`}>
|
onChange={handleInputChange}
|
||||||
Learn{' '}
|
resize="vertical"
|
||||||
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
|
maxLength={4096}
|
||||||
->
|
borderColor="black"
|
||||||
</span>
|
/>
|
||||||
</h2>
|
<Box textAlign="right" fontSize="sm">
|
||||||
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
|
{inputText.length} / 4096
|
||||||
Learn about Next.js in an interactive course with quizzes!
|
</Box>
|
||||||
</p>
|
</FormControl>
|
||||||
</a>
|
|
||||||
|
|
||||||
<a
|
<HStack width="full" justifyContent="space-between">
|
||||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
|
<FormControl isRequired width="45%">
|
||||||
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
|
<FormLabel htmlFor='voice'>Voice</FormLabel>
|
||||||
target="_blank"
|
<Select
|
||||||
rel="noopener noreferrer"
|
id='voice'
|
||||||
>
|
value={voice}
|
||||||
<h2 className={`mb-3 text-2xl font-semibold`}>
|
onChange={(e) => setVoice(e.target.value)}
|
||||||
Templates{' '}
|
variant="outline"
|
||||||
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
|
placeholder="Select voice"
|
||||||
->
|
borderColor="black"
|
||||||
</span>
|
focusBorderColor="black"
|
||||||
</h2>
|
colorScheme="blackAlpha"
|
||||||
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
|
_hover={{ borderColor: 'gray.400' }} // Optional: style for hover state
|
||||||
Discover and deploy boilerplate example Next.js projects.
|
>
|
||||||
</p>
|
{/* List of supported voices */}
|
||||||
</a>
|
<option value='alloy'>Alloy</option>
|
||||||
|
<option value='echo'>Echo</option>
|
||||||
|
<option value='fable'>Fable</option>
|
||||||
|
<option value='onyx'>Onyx</option>
|
||||||
|
<option value='nova'>Nova</option>
|
||||||
|
<option value='shimmer'>Shimmer</option>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<a
|
<FormControl width="40%" mt='-15'>
|
||||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
|
<FormLabel htmlFor='speed'>Speed </FormLabel>
|
||||||
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
|
<Slider
|
||||||
target="_blank"
|
id='speed'
|
||||||
rel="noopener noreferrer"
|
defaultValue={1}
|
||||||
>
|
min={0.25}
|
||||||
<h2 className={`mb-3 text-2xl font-semibold`}>
|
max={4}
|
||||||
Deploy{' '}
|
step={0.25}
|
||||||
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
|
onChange={(v) => setSliderValue(v)}
|
||||||
->
|
onMouseEnter={() => setShowTooltip(true)}
|
||||||
</span>
|
onMouseLeave={() => setShowTooltip(false)}
|
||||||
</h2>
|
ref={sliderRef}
|
||||||
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
|
aria-label='slider-ex-1'
|
||||||
Instantly deploy your Next.js site to a shareable URL with Vercel.
|
>
|
||||||
</p>
|
<SliderTrack bg="gray">
|
||||||
</a>
|
<SliderFilledTrack bg="black" />
|
||||||
</div>
|
</SliderTrack>
|
||||||
</main>
|
<Tooltip
|
||||||
)
|
hasArrow
|
||||||
|
bg='black'
|
||||||
|
color='white'
|
||||||
|
placement='bottom'
|
||||||
|
isOpen={showTooltip}
|
||||||
|
label={`${(sliderValue).toFixed(2)}x`}
|
||||||
|
>
|
||||||
|
<SliderThumb />
|
||||||
|
</Tooltip>
|
||||||
|
</Slider>
|
||||||
|
</FormControl>
|
||||||
|
</HStack>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
bg='black'
|
||||||
|
color={'white'}
|
||||||
|
colorScheme='black'
|
||||||
|
borderColor="black"
|
||||||
|
type='submit'
|
||||||
|
isLoading={isSubmitting}
|
||||||
|
loadingText="Generating..."
|
||||||
|
>
|
||||||
|
Create Speech
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{isSubmitting && (
|
||||||
|
<Spinner
|
||||||
|
thickness="4px"
|
||||||
|
speed="0.65s"
|
||||||
|
emptyColor="gray.200"
|
||||||
|
color="black"
|
||||||
|
size="md"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{audioUrl && (
|
||||||
|
<>
|
||||||
|
<audio controls src={audioUrl}>
|
||||||
|
Your browser does not support the audio element.
|
||||||
|
</audio>
|
||||||
|
<Button onClick={handleDownload}>Download MP3</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</Container>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
backgroundImage: {
|
|
||||||
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
|
|
||||||
'gradient-conic':
|
|
||||||
'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user