From 6131fd8fc6cb1245ccfbc5d03d33ffd1498e83f4 Mon Sep 17 00:00:00 2001
From: alyssaf16 <alyssa_feinberg@brown.edu>
Date: Mon, 8 Jul 2024 15:12:16 -0400
Subject: Speech to phonemes progress

---
 src/client/views/nodes/AudioBox.tsx | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

(limited to 'src/client/views/nodes/AudioBox.tsx')

diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx
index 9deed4de4..5d0ed7eab 100644
--- a/src/client/views/nodes/AudioBox.tsx
+++ b/src/client/views/nodes/AudioBox.tsx
@@ -10,7 +10,7 @@ import { DateField } from '../../../fields/DateField';
 import { Doc } from '../../../fields/Doc';
 import { DocData } from '../../../fields/DocSymbols';
 import { ComputedField } from '../../../fields/ScriptField';
-import { Cast, DateCast, NumCast } from '../../../fields/Types';
+import { Cast, DateCast, DocCast, NumCast } from '../../../fields/Types';
 import { AudioField, nullAudio } from '../../../fields/URLField';
 import { formatTime } from '../../../Utils';
 import { Docs } from '../../documents/Documents';
@@ -29,6 +29,7 @@ import './AudioBox.scss';
 import { DocumentView } from './DocumentView';
 import { FieldView, FieldViewProps } from './FieldView';
 import { OpenWhere } from './OpenWhere';
+import axios from 'axios';
 
 /**
  * AudioBox
@@ -257,6 +258,8 @@ export class AudioBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             const [{ result }] = await Networking.UploadFilesToServer({ file: e.data });
             if (!(result instanceof Error)) {
                 this.Document[this.fieldKey] = new AudioField(result.accessPaths.agnostic.client);
+                this.Document.url = result.accessPaths.agnostic.client;
+                await this.pushInfo();
             }
         };
         this._recordStart = new Date().getTime();
@@ -284,9 +287,23 @@ export class AudioBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         }
     };
 
+    pushInfo = async () => {
+        const audio = {
+            file: this.path,
+        };
+        const response = await axios.post('http://localhost:105/recognize/', audio, {
+            headers: {
+                'Content-Type': 'application/json',
+            },
+        });
+        this.Document[DocData].phoneticTranscription = response.data['transcription'];
+        console.log('RESPONSE: ' + response.data['transcription']);
+    };
+
     // context menu
     specificContextMenu = (): void => {
         const funcs: ContextMenuProps[] = [];
+        // funcs.push({ description: 'Push info', event: this.pushInfo, icon: 'redo-alt' });
         funcs.push({
             description: (this.layoutDoc.hideAnchors ? "Don't hide" : 'Hide') + ' anchors',
             event: () => { this.layoutDoc.hideAnchors = !this.layoutDoc.hideAnchors; }, // prettier-ignore
-- 
cgit v1.2.3-70-g09d2

