diff options
Diffstat (limited to 'src/client/views/nodes/ComparisonBox.tsx')
-rw-r--r-- | src/client/views/nodes/ComparisonBox.tsx | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index d2a032d79..9fb8bc4d6 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -316,6 +316,10 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() ContextMenu.Instance.setLangIndex(ind); }; + /** + * Determine which language the speech to text tool is in. + * @returns + */ convertAbr = () => { switch (this.recognition.lang) { case 'en-US': return 'English'; //prettier-ignore @@ -340,12 +344,58 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() ContextMenu.Instance.displayMenu(x, y); }; + /** + * Creates an AudioBox to record a user's audio. + */ evaluatePronunciation = () => { const newAudio = Docs.Create.AudioDocument(nullAudio, { _width: 200, _height: 100 }); this.Document.audio = newAudio[DocData]; this._props.DocumentView?.()._props.addDocument?.(newAudio); }; + /** + * Gets the transcription of an audio recording by sending the + * recording to backend. + */ + pushInfo = async () => { + const audio = { + file: this._audio.url, + }; + const response = await axios.post('http://localhost:105/recognize/', audio, { + headers: { + 'Content-Type': 'application/json', + }, + }); + this.Document.phoneticTranscription = response.data['transcription']; + }; + + /** + * Extracts the id of the youtube video url. + * @param url + * @returns + */ + getYouTubeVideoId = (url: string) => { + const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/; + const match = url.match(regExp); + return match && match[2].length === 11 ? match[2] : null; + }; + + /** + * Gets the transcript of a youtube video by sending the video url to the backend. + * @returns transcription of youtube recording + */ + youtubeUpload = async () => { + const audio = { + file: this.getYouTubeVideoId(StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text)), + }; + const response = await axios.post('http://localhost:105/youtube/', audio, { + headers: { + 'Content-Type': 'application/json', + }, + }); + return response.data['transcription']; + }; + createFlashcardPile(collectionArr: Doc[], gpt: boolean) { const newCol = Docs.Create.CarouselDocument(collectionArr, { _width: NumCast(this.layoutDoc['_' + this._props.fieldKey + '_width'], 250) + 50, @@ -447,8 +497,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() } else if (callType === GPTCallType.FLASHCARD) { this._loading = false; return res; - } else if (callType === GPTCallType.STACK) { - /* empty */ } this._loading = false; return res; |