mirror of
https://github.com/steveseguin/captionninja.git
synced 2026-10-09 17:49:30 +00:00
Add files via upload
This commit is contained in:
+28
-21
@@ -225,7 +225,7 @@
|
||||
<br /><br />
|
||||
Please note that this app uses your default microphone as the audio input source. You sometimes can change the default audio source via the browser's setting, but you can also change it at your system level by changing the default recording device. You can also change audio sources by using a Virtual Audio Cable, <a href='https://www.vb-audio.com/Cable/'> such as this one.</a> Using it, it becomes possible to select other sources, including microphones, speakers, and other applications.
|
||||
<br /><br />
|
||||
The translation component is based on code from Mozilla <a href="https://github.com/mozilla/translate">https://github.com/mozilla/translate</a>. If your language is missing though, or you want better results, I have a version <a href='https://caption.ninja/translate_premium' target='_blank'>powered by Google Cloud Translation here</a>. Check out more options and details on <a href='https://github.com/steveseguin/captionninja'>GitHub</a>.
|
||||
The translation component is based on code from Mozilla <a href="https://github.com/mozilla/translate">https://github.com/mozilla/translate</a>. If your language is missing though, or you want better results, I have a version <a href='https://caption.ninja/translate_premium''>powered by Google Cloud Translation here</a>. Check out more options and details on <a href='https://github.com/steveseguin/captionninja'>GitHub</a>.
|
||||
<br /><br />
|
||||
<label>
|
||||
From
|
||||
@@ -556,17 +556,25 @@ langFrom.addEventListener("change", e => {
|
||||
const setToCode = (currentTo !== langFrom.value)
|
||||
? currentTo
|
||||
: findFirstSupportedTo();
|
||||
myLangCode = langFrom.value.split("-")[0];
|
||||
if (myLangCode in supportedFromCodes) {
|
||||
console.log("guessing input language is", myLangCode);
|
||||
setFromCode = myLangCode;
|
||||
}
|
||||
recognition.stop();
|
||||
myLangCode = langFrom.value.split("-")[0];
|
||||
if (myLangCode in supportedFromCodes) {
|
||||
console.log("setting input language to", myLangCode);
|
||||
myLang = myLangCode;
|
||||
// Update URL parameter
|
||||
updateURL("lang=" + myLangCode, true);
|
||||
// Update recognition language
|
||||
if (recognition) {
|
||||
recognition.lang = myLangCode;
|
||||
}
|
||||
}
|
||||
recognition.stop();
|
||||
setLangs(langTo, supportedToCodes, setToCode, langFrom.value);
|
||||
loadModel();
|
||||
});
|
||||
langTo.addEventListener("change", e => {
|
||||
currentTo = langTo.value;
|
||||
// Update URL parameter
|
||||
updateURL("translate=" + currentTo, true);
|
||||
loadModel();
|
||||
});
|
||||
const setLangs = (selector, langsToSet, value, exlcude) => {
|
||||
@@ -623,7 +631,6 @@ function updateURL(param, force=false) {
|
||||
} else {
|
||||
href.searchParams.set(para[0].toLowerCase(), para[1]);
|
||||
}
|
||||
log(href.toString());
|
||||
window.history.pushState({path:href.toString()},'',href.toString());
|
||||
}
|
||||
}
|
||||
@@ -925,19 +932,19 @@ var sanitize = function(string) {
|
||||
.trim();
|
||||
};
|
||||
function setup(){
|
||||
if ('webkitSpeechRecognition' in window){
|
||||
recognition = new webkitSpeechRecognition();
|
||||
if (myLang && myLangCode){
|
||||
if (myLang.split("-")[0] == myLangCode){
|
||||
recognition.lang = myLang;
|
||||
} else {
|
||||
recognition.lang = myLangCode;
|
||||
}
|
||||
} else if (myLangCode){
|
||||
recognition.lang = myLangCode;
|
||||
} else if (myLang){
|
||||
recognition.lang = myLang;
|
||||
}
|
||||
if ('webkitSpeechRecognition' in window){
|
||||
recognition = new webkitSpeechRecognition();
|
||||
if (myLang && myLangCode){
|
||||
if (myLang.split("-")[0] == myLangCode){
|
||||
recognition.lang = myLang;
|
||||
} else {
|
||||
recognition.lang = myLangCode;
|
||||
}
|
||||
} else if (myLangCode){
|
||||
recognition.lang = myLangCode;
|
||||
} else if (myLang){
|
||||
recognition.lang = myLang;
|
||||
}
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = true;
|
||||
recognition.onstart = function(){
|
||||
|
||||
+36
-17
@@ -795,21 +795,46 @@ function updateTrans(translatedText, isIncremental) {
|
||||
}
|
||||
langFrom.addEventListener("change", e => {
|
||||
myLangCode = e.target.value;
|
||||
console.log(myLangCode)
|
||||
if (myLang.split("-")[0].toLowerCase() !== myLangCode){
|
||||
setStorage("myLang", myLangCode, 999999);
|
||||
updateURL("lang="+myLangCode, true);
|
||||
console.log("Source language changed to:", myLangCode);
|
||||
|
||||
// Always update storage and URL, regardless of previous language
|
||||
setStorage("myLang", myLangCode, 999999);
|
||||
updateURL("lang="+myLangCode, true);
|
||||
|
||||
// Always restart recognition with new language
|
||||
if (recognition) {
|
||||
recognition.onend = null;
|
||||
recognition.stop();
|
||||
recognition = null;
|
||||
setup();
|
||||
}
|
||||
myLang = myLangCode; // Update the myLang variable directly
|
||||
setup();
|
||||
});
|
||||
langTo.addEventListener("change", e => {
|
||||
targetCode = e.target.value;
|
||||
console.log("Target language changed to:", targetCode);
|
||||
updateURL("translate="+targetCode, true);
|
||||
console.log(targetCode);
|
||||
setStorage("targetCode", targetCode, 999999);
|
||||
|
||||
// If there's text in the input field, translate it immediately with the new target language
|
||||
const currentText = document.getElementById("input").value.trim();
|
||||
if (currentText && document.getElementById("enabledTranscription").checked) {
|
||||
if (document.getElementById("fullContext").checked) {
|
||||
let fullText = [];
|
||||
if (second_transcription?.trim()) {
|
||||
fullText.push(second_transcription.trim().replace(/\.?$/, '.'));
|
||||
}
|
||||
if (last_transcription?.trim()) {
|
||||
fullText.push(last_transcription.trim().replace(/\.?$/, '.'));
|
||||
}
|
||||
if (currentText?.trim()) {
|
||||
fullText.push(currentText.trim().replace(/\.?$/, '.'));
|
||||
}
|
||||
translateIncremental(fullText.join(' '));
|
||||
} else {
|
||||
translateIncremental(currentText);
|
||||
}
|
||||
}
|
||||
});
|
||||
function updateURL(param, force=false) {
|
||||
var para = param.split('=');
|
||||
@@ -937,17 +962,11 @@ function setup(){
|
||||
if ('webkitSpeechRecognition' in window){
|
||||
console.log("Setting up webkitSpeechRecognition");
|
||||
recognition = new webkitSpeechRecognition();
|
||||
if (myLang && myLangCode){
|
||||
if (myLang.split("-")[0] == myLangCode){
|
||||
recognition.lang = myLang;
|
||||
} else {
|
||||
recognition.lang = myLangCode;
|
||||
}
|
||||
} else if (myLangCode){
|
||||
recognition.lang = myLangCode;
|
||||
} else if (myLang){
|
||||
recognition.lang = myLang;
|
||||
}
|
||||
|
||||
// Always use the current myLangCode
|
||||
recognition.lang = myLangCode || myLang || navigator.language || "en-US";
|
||||
console.log("Recognition language set to:", recognition.lang);
|
||||
|
||||
recognition.continuous = true;
|
||||
recognition.interimResults = document.getElementById("incrementalUpdates").checked;
|
||||
recognition.onstart = function(){
|
||||
|
||||
Reference in New Issue
Block a user