From 7288e9ace73ec88cb014600bc617f7915174c249 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 25 Mar 2021 16:48:46 +0100 Subject: [PATCH] Text to Speech (#2) * Initial TTS scrapping implemented * Audio & copy buttons added * TTS langs mapping fix * Webkit audio api fix * Added TTS-related testing * Last tweaks --- components/TranslationArea.tsx | 69 +++++++++++++++++++++++++------- cypress/integration/app.spec.ts | 49 ++++++++++++++--------- hooks/index.ts | 1 + hooks/useAudioFromBuffer.ts | 60 +++++++++++++++++++++++++++ package.json | 4 +- pages/[[...slug]].tsx | 22 +++++++--- tests/pages/[[...slug]].test.tsx | 36 +++++++++++++---- tests/utils/translate.test.ts | 20 ++++++++- utils/languages.json | 3 +- utils/translate.ts | 38 +++++++++++++++++- yarn.lock | 49 +++++++++++++++++++++++ 11 files changed, 302 insertions(+), 49 deletions(-) create mode 100644 hooks/useAudioFromBuffer.ts diff --git a/components/TranslationArea.tsx b/components/TranslationArea.tsx index 659aa54..53ee1ed 100644 --- a/components/TranslationArea.tsx +++ b/components/TranslationArea.tsx @@ -1,24 +1,65 @@ import { FC, ChangeEvent } from "react"; -import { Textarea, useBreakpointValue } from "@chakra-ui/react"; +import { Box, HStack, Textarea, IconButton, Tooltip, useBreakpointValue, useClipboard } from "@chakra-ui/react"; +import { FaCopy, FaCheck, FaPlay, FaStop } from "react-icons/fa"; +import { useAudioFromBuffer } from "../hooks"; type Props = { value: string, onChange?: (e: ChangeEvent) => void, - readOnly?: true + readOnly?: true, + audio?: number[], + canCopy?: boolean, [key: string]: any }; -const TranslationArea: FC = ({ value, onChange, readOnly, ...props }) => ( -