johnpaulbin commited on
Commit
c54478b
·
verified ·
1 Parent(s): c827239

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -57,11 +57,10 @@ def home():
57
  }
58
  let recognition = new window.SpeechRecognition();
59
  recognition.continuous = true;
60
- recognition.interimResults = true;
61
  let liveOutput = document.getElementById('transcription');
62
  let lastTranscription = '';
63
- let intervalId = null;
64
- let delimiterId = null;
65
  recognition.onresult = (event) => {
66
  let currentTranscription = '';
67
  for (const result of event.results) {
@@ -70,22 +69,21 @@ def home():
70
  liveOutput.textContent = currentTranscription;
71
  if (lastTranscription !== currentTranscription) {
72
  lastTranscription = currentTranscription;
73
- console.log(currentTranscription);
74
  }
75
  };
 
76
  recognition.onerror = (event) => {
77
  console.error('Speech recognition error', event.error);
78
  };
79
 
80
- function sendTranscriptionToServer() {
81
  let username = document.getElementById('username').value;
82
- // Extract the latest entry after the last delimiter
83
- let latestEntry = lastTranscription.substring(lastTranscription.lastIndexOf('DELIMIN') + 7);
84
  $.ajax({
85
  url: 'https://johnpaulbin-api-test-stt.hf.space/' + username,
86
  type: 'POST',
87
  contentType: 'application/json',
88
- data: JSON.stringify({ transcription: latestEntry }),
89
  success: function(response) {
90
  console.log('Transcription sent', response);
91
  },
@@ -95,25 +93,17 @@ def home():
95
  });
96
  }
97
 
98
- function appendDelimiter() {
99
- lastTranscription += 'DELIMIN';
100
- currentTranscription += 'DELIMIN';
101
- }
102
-
103
  document.getElementById('start').addEventListener('click', () => {
104
  recognition.start();
105
- intervalId = setInterval(sendTranscriptionToServer, 350);
106
- delimiterId = setInterval(appendDelimiter, 3500);
107
  });
108
  document.getElementById('stop').addEventListener('click', () => {
109
  recognition.stop();
110
- clearInterval(intervalId);
111
- clearInterval(delimiterId);
112
  });
113
  </script>
114
  </body>
115
  </html>
116
 
 
117
  """
118
  return Response(html_content, mimetype='text/html')
119
 
 
57
  }
58
  let recognition = new window.SpeechRecognition();
59
  recognition.continuous = true;
60
+ recognition.interimResults = false;
61
  let liveOutput = document.getElementById('transcription');
62
  let lastTranscription = '';
63
+
 
64
  recognition.onresult = (event) => {
65
  let currentTranscription = '';
66
  for (const result of event.results) {
 
69
  liveOutput.textContent = currentTranscription;
70
  if (lastTranscription !== currentTranscription) {
71
  lastTranscription = currentTranscription;
72
+ sendTranscriptionToServer(currentTranscription);
73
  }
74
  };
75
+
76
  recognition.onerror = (event) => {
77
  console.error('Speech recognition error', event.error);
78
  };
79
 
80
+ function sendTranscriptionToServer(transcription) {
81
  let username = document.getElementById('username').value;
 
 
82
  $.ajax({
83
  url: 'https://johnpaulbin-api-test-stt.hf.space/' + username,
84
  type: 'POST',
85
  contentType: 'application/json',
86
+ data: JSON.stringify({ transcription: transcription }),
87
  success: function(response) {
88
  console.log('Transcription sent', response);
89
  },
 
93
  });
94
  }
95
 
 
 
 
 
 
96
  document.getElementById('start').addEventListener('click', () => {
97
  recognition.start();
 
 
98
  });
99
  document.getElementById('stop').addEventListener('click', () => {
100
  recognition.stop();
 
 
101
  });
102
  </script>
103
  </body>
104
  </html>
105
 
106
+
107
  """
108
  return Response(html_content, mimetype='text/html')
109