Tri4 commited on
Commit
fa16223
·
verified ·
1 Parent(s): c6730f8

Update static/js/design.js

Browse files
Files changed (1) hide show
  1. static/js/design.js +16 -10
static/js/design.js CHANGED
@@ -2,9 +2,12 @@ let isRecording = false;
2
  let mediaRecorder;
3
  let recordedChunks = [];
4
 
 
5
  const micContainer = document.getElementsByClassName('mic-container')[0];
6
  const circle = micContainer.getElementsByClassName('circle')[0];
 
7
 
 
8
  micContainer.addEventListener('click', function () {
9
  if (!isRecording) {
10
  startRecording();
@@ -25,7 +28,7 @@ function startRecording() {
25
 
26
  // Update UI for recording
27
  circle.classList.add('active');
28
- document.getElementById('output').textContent = 'Recording...';
29
  isRecording = true;
30
  })
31
  .catch(function (err) {
@@ -43,29 +46,32 @@ function stopRecording() {
43
 
44
  // Update UI after recording
45
  circle.classList.remove('active');
46
- document.getElementById('output').textContent = 'Click to Transcribe';
47
 
48
- // Handle the Transcribe button click
49
- document.getElementById('output').addEventListener('click', function () {
50
- transcribeAudio(blob);
51
- });
52
 
53
  isRecording = false;
54
  };
55
  }
56
 
57
- function transcribeAudio(blob) {
 
 
 
 
 
58
  const formData = new FormData();
59
  formData.append('audio', blob, 'audio.webm');
60
 
61
- //fetch('https://tri4-semalab.hf.space/transcribe', { // https://jikoni-semabox.hf.space/transcribe
62
- fetch('https://jikoni-semabox.hf.space/transcribe', { // https://tri4-semalab.hf.space/transcribe
63
  method: 'POST',
64
  body: formData
65
  })
66
  .then(response => response.json())
67
  .then(data => {
68
- document.getElementById('output').textContent = data.transcription;
69
  })
70
  .catch(error => {
71
  console.error('Error:', error);
 
2
  let mediaRecorder;
3
  let recordedChunks = [];
4
 
5
+ // Get the elements
6
  const micContainer = document.getElementsByClassName('mic-container')[0];
7
  const circle = micContainer.getElementsByClassName('circle')[0];
8
+ const outputContainer = document.getElementById('output');
9
 
10
+ // Handle the click event for the microphone container
11
  micContainer.addEventListener('click', function () {
12
  if (!isRecording) {
13
  startRecording();
 
28
 
29
  // Update UI for recording
30
  circle.classList.add('active');
31
+ outputContainer.textContent = 'Recording...';
32
  isRecording = true;
33
  })
34
  .catch(function (err) {
 
46
 
47
  // Update UI after recording
48
  circle.classList.remove('active');
49
+ outputContainer.textContent = 'Click to Transcribe';
50
 
51
+ // Ensure only one event listener is attached
52
+ outputContainer.removeEventListener('click', handleTranscribeClick);
53
+ outputContainer.addEventListener('click', handleTranscribeClick);
 
54
 
55
  isRecording = false;
56
  };
57
  }
58
 
59
+ function handleTranscribeClick() {
60
+ transcribeAudio();
61
+ }
62
+
63
+ function transcribeAudio() {
64
+ const blob = new Blob(recordedChunks, { type: 'audio/webm' });
65
  const formData = new FormData();
66
  formData.append('audio', blob, 'audio.webm');
67
 
68
+ fetch('https://tri4-semalab.hf.space/transcribe', {
 
69
  method: 'POST',
70
  body: formData
71
  })
72
  .then(response => response.json())
73
  .then(data => {
74
+ outputContainer.textContent = `Transcription: ${data.transcription}`;
75
  })
76
  .catch(error => {
77
  console.error('Error:', error);