-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ndrean/audio-transcription
#18 1) adding audio transcription
- Loading branch information
Showing
15 changed files
with
1,494 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export default { | ||
mounted() { | ||
let mediaRecorder, | ||
audioChunks = []; | ||
|
||
// Defining the elements and styles to be used during recording | ||
// and shown on the HTML. | ||
const recordButton = document.getElementById("record"), | ||
audioElement = document.getElementById("audio"), | ||
text = document.getElementById("text"), | ||
blue = ["bg-blue-500", "hover:bg-blue-700"], | ||
pulseGreen = ["bg-green-500", "hover:bg-green-700", "animate-pulse"]; | ||
|
||
|
||
_this = this; | ||
|
||
// Adding event listener for "click" event | ||
recordButton.addEventListener("click", () => { | ||
|
||
// Check if it's recording. | ||
// If it is, we stop the record and update the elements. | ||
if (mediaRecorder && mediaRecorder.state === "recording") { | ||
mediaRecorder.stop(); | ||
text.textContent = "Record"; | ||
} | ||
|
||
// Otherwise, it means the user wants to start recording. | ||
else { | ||
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => { | ||
|
||
// Instantiate MediaRecorder | ||
mediaRecorder = new MediaRecorder(stream); | ||
mediaRecorder.start(); | ||
|
||
// And update the elements | ||
recordButton.classList.remove(...blue); | ||
recordButton.classList.add(...pulseGreen); | ||
text.textContent = "Stop"; | ||
|
||
// Add "dataavailable" event handler | ||
mediaRecorder.addEventListener("dataavailable", (event) => { | ||
audioChunks.push(event.data); | ||
}); | ||
|
||
// Add "stop" event handler for when the recording stops. | ||
mediaRecorder.addEventListener("stop", () => { | ||
const audioBlob = new Blob(audioChunks); | ||
// the source of the audio element | ||
audioElement.src = URL.createObjectURL(audioBlob); | ||
|
||
_this.upload("speech", [audioBlob]); | ||
audioChunks = []; | ||
recordButton.classList.remove(...pulseGreen); | ||
recordButton.classList.add(...blue); | ||
}); | ||
}); | ||
} | ||
}); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.