import { Box, FormControlLabel, Radio, RadioGroup } from '@mui/material'; import React, { useState } from 'react'; import ToolContent from '@components/ToolContent'; import { ToolComponentProps } from '@tools/defineTool'; import { GetGroupsType } from '@components/options/ToolOptions'; import { InitialValuesType } from './types'; import ToolAudioInput from '@components/input/ToolAudioInput'; import ToolFileResult from '@components/result/ToolFileResult'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import RadioWithTextField from '@components/options/RadioWithTextField'; import { changeAudioSpeed } from './service'; const initialValues: InitialValuesType = { newSpeed: 2, outputFormat: 'mp3' }; const formatOptions = [ { label: 'MP3', value: 'mp3' }, { label: 'AAC', value: 'aac' }, { label: 'WAV', value: 'wav' } ]; export default function ChangeSpeed({ title, longDescription }: ToolComponentProps) { const [input, setInput] = useState(null); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const compute = async ( optionsValues: InitialValuesType, input: File | null ) => { setLoading(true); try { const newFile = await changeAudioSpeed(input, optionsValues); setResult(newFile); } catch (err) { setResult(null); } finally { setLoading(false); } }; const getGroups: GetGroupsType | null = ({ values, updateField }) => [ { title: 'New Audio Speed', component: ( updateField('newSpeed', Number(val))} description="Default multiplier: 2 means 2x faster" type="number" /> ) }, { title: 'Output Format', component: ( updateField( 'outputFormat', e.target.value as 'mp3' | 'aac' | 'wav' ) } > {formatOptions.map((opt) => ( } label={opt.label} /> ))} ) } ]; return ( } resultComponent={ loading ? ( ) : ( ) } initialValues={initialValues} getGroups={getGroups} setInput={setInput} compute={compute} toolInfo={{ title: `What is ${title}?`, description: longDescription }} /> ); }