[Update] Add WordFilter.
This commit is contained in:
56
data.js
56
data.js
@@ -82,59 +82,3 @@ export const generateTestData = (num) => {
|
||||
|
||||
return testDataArray;
|
||||
};
|
||||
|
||||
export const word_filter_list = [
|
||||
{ value: "りんご", is_redoable: false },
|
||||
{ value: "forest", is_redoable: false },
|
||||
{ value: "もり", is_redoable: false },
|
||||
{ value: "elephant", is_redoable: false },
|
||||
{ value: "penguin", is_redoable: false },
|
||||
{ value: "やま", is_redoable: false },
|
||||
{ value: "notebook", is_redoable: false },
|
||||
{ value: "zebra", is_redoable: false },
|
||||
{ value: "ちょう", is_redoable: false },
|
||||
{ value: "dinosaur", is_redoable: false },
|
||||
{ value: "たいこ", is_redoable: false },
|
||||
{ value: "カンガルー", is_redoable: false },
|
||||
{ value: "ふうせん", is_redoable: false },
|
||||
{ value: "candle", is_redoable: false },
|
||||
{ value: "tiger", is_redoable: false },
|
||||
{ value: "umbrella", is_redoable: false },
|
||||
{ value: "garden", is_redoable: false },
|
||||
{ value: "ペンギン", is_redoable: false },
|
||||
{ value: "ひまわり", is_redoable: false },
|
||||
{ value: "kangaroo", is_redoable: false },
|
||||
{ value: "とうだい", is_redoable: false },
|
||||
{ value: "シロフォン", is_redoable: false },
|
||||
{ value: "ひこうき", is_redoable: false },
|
||||
{ value: "しろ", is_redoable: false },
|
||||
{ value: "しあわせ", is_redoable: false },
|
||||
{ value: "xylophone", is_redoable: false },
|
||||
{ value: "volcano", is_redoable: false },
|
||||
{ value: "drum", is_redoable: false },
|
||||
{ value: "lighthouse", is_redoable: false },
|
||||
{ value: "quicksand", is_redoable: false },
|
||||
{ value: "airplane", is_redoable: false },
|
||||
{ value: "しまうま", is_redoable: false },
|
||||
{ value: "sunflower", is_redoable: false },
|
||||
{ value: "ジャングル", is_redoable: false },
|
||||
{ value: "くじら", is_redoable: false },
|
||||
{ value: "apple", is_redoable: false },
|
||||
{ value: "island", is_redoable: false },
|
||||
{ value: "ocean", is_redoable: false },
|
||||
{ value: "rainbow", is_redoable: false },
|
||||
{ value: "castle", is_redoable: false },
|
||||
{ value: "かさ", is_redoable: false },
|
||||
{ value: "ぞう", is_redoable: false },
|
||||
{ value: "balloon", is_redoable: false },
|
||||
{ value: "happiness", is_redoable: false },
|
||||
{ value: "whale", is_redoable: false },
|
||||
{ value: "にじ", is_redoable: false },
|
||||
{ value: "ヨット", is_redoable: false },
|
||||
{ value: "しま", is_redoable: false },
|
||||
{ value: "かざん", is_redoable: false },
|
||||
{ value: "ノート", is_redoable: false },
|
||||
{ value: "mountain", is_redoable: false },
|
||||
{ value: "うみ", is_redoable: false },
|
||||
{ value: "ジャングル", is_redoable: false },
|
||||
];
|
||||
@@ -780,36 +780,11 @@ class Controller:
|
||||
|
||||
@staticmethod
|
||||
def setMicWordFilter(data, *args, **kwargs) -> dict:
|
||||
data = str(data)
|
||||
data = [w.strip() for w in data.split(",") if len(w.strip()) > 0]
|
||||
# Copy the list
|
||||
new_mic_word_filter_list = config.MIC_WORD_FILTER
|
||||
new_added_value = []
|
||||
for value in data:
|
||||
if value in new_mic_word_filter_list:
|
||||
# If the value is already in the list, do nothing.
|
||||
pass
|
||||
else:
|
||||
new_mic_word_filter_list.append(value)
|
||||
new_added_value.append(value)
|
||||
config.MIC_WORD_FILTER = new_mic_word_filter_list
|
||||
|
||||
config.MIC_WORD_FILTER = sorted(set(data), key=data.index)
|
||||
model.resetKeywordProcessor()
|
||||
model.addKeywords()
|
||||
return {"status":200, "result":config.MIC_WORD_FILTER}
|
||||
|
||||
@staticmethod
|
||||
def delMicWordFilter(data, *args, **kwargs) -> dict:
|
||||
try:
|
||||
new_mic_word_filter_list = config.MIC_WORD_FILTER
|
||||
new_mic_word_filter_list.remove(str(data))
|
||||
config.MIC_WORD_FILTER = new_mic_word_filter_list
|
||||
model.resetKeywordProcessor()
|
||||
model.addKeywords()
|
||||
except Exception:
|
||||
printLog("Delete Mic Word Filter", "There was no the target word in config.MIC_WORD_FILTER")
|
||||
return {"status":200, "result":config.MIC_WORD_FILTER}
|
||||
|
||||
@staticmethod
|
||||
def getMicAvgLogprob(*args, **kwargs) -> dict:
|
||||
return {"status":200, "result":config.MIC_AVG_LOGPROB}
|
||||
|
||||
@@ -196,7 +196,6 @@ mapping = {
|
||||
|
||||
"/get/data/mic_word_filter": {"status": True, "variable":controller.getMicWordFilter},
|
||||
"/set/data/mic_word_filter": {"status": True, "variable":controller.setMicWordFilter},
|
||||
"/delete/data/mic_word_filter": {"status": True, "variable":controller.delMicWordFilter},
|
||||
|
||||
"/get/data/auto_speaker_select": {"status": True, "variable":controller.getAutoSpeakerSelect},
|
||||
"/set/enable/auto_speaker_select": {"status": True, "variable":controller.setEnableAutoSpeakerSelect},
|
||||
@@ -523,8 +522,6 @@ if __name__ == "__main__":
|
||||
data = 5
|
||||
case "/set//data/mic_word_filter":
|
||||
data = "test0, test1, test2"
|
||||
case "/delete/data/mic_word_filter":
|
||||
data = "test1"
|
||||
case "/set/data/selected_speaker_device":
|
||||
data = "スピーカー (Realtek High Definition Audio)"
|
||||
case "/set/data/speaker_threshold":
|
||||
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
useMicRecordTimeout,
|
||||
useMicPhraseTimeout,
|
||||
useMicMaxWords,
|
||||
useMicWordFilterList,
|
||||
useSpeakerRecordTimeout,
|
||||
useSpeakerPhraseTimeout,
|
||||
useSpeakerMaxWords,
|
||||
@@ -109,6 +110,7 @@ const StartPythonFacadeComponent = () => {
|
||||
const { getMicRecordTimeout } = useMicRecordTimeout();
|
||||
const { getMicPhraseTimeout } = useMicPhraseTimeout();
|
||||
const { getMicMaxWords } = useMicMaxWords();
|
||||
const { getMicWordFilterList } = useMicWordFilterList();
|
||||
|
||||
const { getSpeakerRecordTimeout } = useSpeakerRecordTimeout();
|
||||
const { getSpeakerPhraseTimeout } = useSpeakerPhraseTimeout();
|
||||
@@ -160,6 +162,7 @@ const StartPythonFacadeComponent = () => {
|
||||
getMicRecordTimeout();
|
||||
getMicPhraseTimeout();
|
||||
getMicMaxWords();
|
||||
getMicWordFilterList();
|
||||
|
||||
getSpeakerRecordTimeout();
|
||||
getSpeakerPhraseTimeout();
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import styles from "./WordFilter.module.scss";
|
||||
import { _Entry } from "../_atoms/_entry/_Entry";
|
||||
import { useState } from "react";
|
||||
import { useStore_WordFilterList, useStore_IsOpenedWordFilterList } from "@store";
|
||||
import { useStore_IsOpenedMicWordFilterList } from "@store";
|
||||
import { useMicWordFilterList } from "@logics_configs";
|
||||
|
||||
export const WordFilter = () => {
|
||||
const [input_value, setInputValue] = useState();
|
||||
const { currentWordFilterList, updateWordFilterList } = useStore_WordFilterList();
|
||||
const { currentIsOpenedWordFilterList, updateIsOpenedWordFilterList } = useStore_IsOpenedWordFilterList();
|
||||
const [input_value, setInputValue] = useState("");
|
||||
const { currentMicWordFilterList, updateMicWordFilterList, setMicWordFilterList } = useMicWordFilterList();
|
||||
const { currentIsOpenedMicWordFilterList, updateIsOpenedMicWordFilterList } = useStore_IsOpenedMicWordFilterList();
|
||||
|
||||
const extractRedoableFalseItem = (updated_list) => {
|
||||
return updated_list.filter(item => {
|
||||
if (item.is_redoable === false) return true;
|
||||
});
|
||||
};
|
||||
|
||||
const onChangeEntry = (e) => {
|
||||
setInputValue(e.target.value);
|
||||
@@ -13,37 +21,43 @@ export const WordFilter = () => {
|
||||
|
||||
const addWords = () => {
|
||||
if (input_value === undefined) return;
|
||||
const input_value_array = input_value.split(",");
|
||||
|
||||
let updated_list = [...currentWordFilterList.data];
|
||||
|
||||
for (let each_input_value of input_value_array) {
|
||||
each_input_value = each_input_value.trim();
|
||||
if (each_input_value) {
|
||||
const target_item = updated_list.find((item) => item.value === each_input_value);
|
||||
if (target_item === undefined) {
|
||||
// Add
|
||||
updated_list = [...updated_list, { value: each_input_value, is_redoable: false }];
|
||||
} else {
|
||||
// Update
|
||||
updated_list = updated_list.map(item =>
|
||||
item.value === each_input_value ? { ...item, is_redoable: false } : item
|
||||
);
|
||||
updateMicWordFilterList((prev_list) => {
|
||||
const input_value_array = input_value.split(",");
|
||||
let updated_list = [...prev_list.data];
|
||||
for (let each_input_value of input_value_array) {
|
||||
each_input_value = each_input_value.trim();
|
||||
if (each_input_value) {
|
||||
const target_item = updated_list.find((item) => item.value === each_input_value);
|
||||
if (target_item === undefined) {
|
||||
// Add
|
||||
updated_list = [...updated_list, { value: each_input_value, is_redoable: false }];
|
||||
} else {
|
||||
// Update
|
||||
updated_list = updated_list.map(item =>
|
||||
item.value === each_input_value ? { ...item, is_redoable: false } : item
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const updated_list_for_restoring = extractRedoableFalseItem(updated_list).map((d) => d.value);
|
||||
setMicWordFilterList(updated_list_for_restoring);
|
||||
return updated_list;
|
||||
});
|
||||
|
||||
updateWordFilterList(updated_list);
|
||||
updateIsOpenedWordFilterList(true);
|
||||
updateIsOpenedMicWordFilterList(true);
|
||||
setInputValue("");
|
||||
};
|
||||
|
||||
|
||||
const updateRedoable = (target_item_value, is_redoable) => {
|
||||
updateWordFilterList((prev_list) =>
|
||||
prev_list.map(item =>
|
||||
updateMicWordFilterList((prev_list) => {
|
||||
const updated_list = prev_list.data.map(item =>
|
||||
item.value === target_item_value ? { ...item, is_redoable: is_redoable } : item
|
||||
)
|
||||
);
|
||||
);
|
||||
const updated_list_for_restoring = extractRedoableFalseItem(updated_list).map((d) => d.value);
|
||||
setMicWordFilterList(updated_list_for_restoring);
|
||||
return updated_list;
|
||||
});
|
||||
};
|
||||
|
||||
const deleteAction = (target_item_value) => {
|
||||
@@ -57,17 +71,17 @@ export const WordFilter = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
{ currentIsOpenedWordFilterList.data &&
|
||||
{ currentIsOpenedMicWordFilterList.data &&
|
||||
<div className={styles.list_section_wrapper}>
|
||||
{
|
||||
currentWordFilterList.data.map((item, index) => {
|
||||
currentMicWordFilterList.data.map((item, index) => {
|
||||
return <WordFilterItem value={item.value} key={index} is_redoable={item.is_redoable} deleteAction={deleteAction} redoAction={redoAction}/>;
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div className={styles.entry_section_wrapper}>
|
||||
<_Entry width="30rem" onChange={onChangeEntry}/>
|
||||
<_Entry width="30rem" onChange={onChangeEntry} ui_variable={input_value}/>
|
||||
<button className={styles.add_button} onClick={addWords}>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -112,20 +126,20 @@ import { useTranslation } from "react-i18next";
|
||||
import ArrowLeftSvg from "@images/arrow_left.svg?react";
|
||||
export const WordFilterListToggleComponent = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { currentIsOpenedWordFilterList, updateIsOpenedWordFilterList } = useStore_IsOpenedWordFilterList();
|
||||
const { currentWordFilterList } = useStore_WordFilterList();
|
||||
const { currentIsOpenedMicWordFilterList, updateIsOpenedMicWordFilterList } = useStore_IsOpenedMicWordFilterList();
|
||||
const { currentMicWordFilterList } = useMicWordFilterList();
|
||||
|
||||
|
||||
const svg_class_names = clsx(styles["arrow_left_svg"], {
|
||||
[styles.to_down]: !currentIsOpenedWordFilterList.data,
|
||||
[styles.to_up]: currentIsOpenedWordFilterList.data
|
||||
[styles.to_down]: !currentIsOpenedMicWordFilterList.data,
|
||||
[styles.to_up]: currentIsOpenedMicWordFilterList.data
|
||||
});
|
||||
|
||||
const OnclickFunction = () => {
|
||||
updateIsOpenedWordFilterList(!currentIsOpenedWordFilterList.data);
|
||||
updateIsOpenedMicWordFilterList(!currentIsOpenedMicWordFilterList.data);
|
||||
};
|
||||
|
||||
const word_filter_list_length = currentWordFilterList.data.filter(item => item.is_redoable === false).length;
|
||||
const word_filter_list_length = currentMicWordFilterList.data.filter(item => item.is_redoable === false).length;
|
||||
|
||||
|
||||
return (
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
|
||||
import {
|
||||
EntryContainer,
|
||||
WordFilterContainer,
|
||||
} from "../_templates/Templates";
|
||||
|
||||
export const Transcription = () => {
|
||||
@@ -32,6 +33,7 @@ const Mic_Container = () => {
|
||||
<MicRecordTimeout_Box />
|
||||
<MicPhraseTimeout_Box />
|
||||
<MicMaxWords_Box />
|
||||
<MicWordFilter_Box />
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -118,6 +120,16 @@ const MicMaxWords_Box = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const MicWordFilter_Box = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<WordFilterContainer
|
||||
label={t("config_page.mic_word_filter.label")}
|
||||
desc={t("config_page.mic_word_filter.desc")}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ export { useEnableAutoClearMessageBox } from "./others/useEnableAutoClearMessage
|
||||
export { useMicRecordTimeout } from "./transcription/useMicRecordTimeout";
|
||||
export { useMicPhraseTimeout } from "./transcription/useMicPhraseTimeout";
|
||||
export { useMicMaxWords } from "./transcription/useMicMaxWords";
|
||||
export { useMicWordFilterList } from "./transcription/useMicWordFilterList";
|
||||
|
||||
export { useSpeakerRecordTimeout } from "./transcription/useSpeakerRecordTimeout";
|
||||
export { useSpeakerPhraseTimeout } from "./transcription/useSpeakerPhraseTimeout";
|
||||
|
||||
24
src-ui/logics/configs/transcription/useMicWordFilterList.js
Normal file
24
src-ui/logics/configs/transcription/useMicWordFilterList.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useStore_MicWordFilterList } from "@store";
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
|
||||
export const useMicWordFilterList = () => {
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
const { currentMicWordFilterList, updateMicWordFilterList, pendingMicWordFilterList } = useStore_MicWordFilterList();
|
||||
|
||||
const getMicWordFilterList = () => {
|
||||
pendingMicWordFilterList();
|
||||
asyncStdoutToPython("/get/data/mic_word_filter");
|
||||
};
|
||||
|
||||
const setMicWordFilterList = (selected_mic_word_filter) => {
|
||||
pendingMicWordFilterList();
|
||||
asyncStdoutToPython("/set/data/mic_word_filter", selected_mic_word_filter);
|
||||
};
|
||||
|
||||
return {
|
||||
currentMicWordFilterList,
|
||||
getMicWordFilterList,
|
||||
updateMicWordFilterList,
|
||||
setMicWordFilterList,
|
||||
};
|
||||
};
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
useMicRecordTimeout,
|
||||
useMicPhraseTimeout,
|
||||
useMicMaxWords,
|
||||
useMicWordFilterList,
|
||||
useSpeakerRecordTimeout,
|
||||
useSpeakerPhraseTimeout,
|
||||
useSpeakerMaxWords,
|
||||
@@ -94,6 +95,7 @@ export const useReceiveRoutes = () => {
|
||||
const { updateMicRecordTimeout } = useMicRecordTimeout();
|
||||
const { updateMicPhraseTimeout } = useMicPhraseTimeout();
|
||||
const { updateMicMaxWords } = useMicMaxWords();
|
||||
const { currentMicWordFilterList, updateMicWordFilterList } = useMicWordFilterList();
|
||||
|
||||
const { updateSpeakerRecordTimeout } = useSpeakerRecordTimeout();
|
||||
const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout();
|
||||
@@ -251,6 +253,35 @@ export const useReceiveRoutes = () => {
|
||||
"/get/data/mic_max_phrases": updateMicMaxWords,
|
||||
"/set/data/mic_max_phrases": updateMicMaxWords,
|
||||
|
||||
"/get/data/mic_word_filter": (payload) => {
|
||||
updateMicWordFilterList((prev_list) => {
|
||||
const updated_list = [...prev_list.data];
|
||||
for (const value of payload) {
|
||||
const existing_item = updated_list.find(item => item.value === value);
|
||||
if (existing_item) {
|
||||
existing_item.is_redoable = false;
|
||||
} else {
|
||||
updated_list.push({ value, is_redoable: false });
|
||||
}
|
||||
}
|
||||
return updated_list;
|
||||
});
|
||||
},
|
||||
"/set/data/mic_word_filter": (payload) => {
|
||||
updateMicWordFilterList((prev_list) => {
|
||||
const updated_list = [...prev_list.data];
|
||||
for (const value of payload) {
|
||||
const existing_item = updated_list.find(item => item.value === value);
|
||||
if (existing_item) {
|
||||
existing_item.is_redoable = false;
|
||||
} else {
|
||||
updated_list.push({ value, is_redoable: false });
|
||||
}
|
||||
}
|
||||
return updated_list;
|
||||
});
|
||||
},
|
||||
|
||||
"/get/data/speaker_record_timeout": updateSpeakerRecordTimeout,
|
||||
"/set/data/speaker_record_timeout": updateSpeakerRecordTimeout,
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
import {
|
||||
translator_status,
|
||||
generateTestData,
|
||||
word_filter_list,
|
||||
} from "@data";
|
||||
|
||||
export const store = {
|
||||
@@ -177,8 +176,8 @@ export const { atomInstance: Atom_SelectableFontFamilyList, useHook: useStore_Se
|
||||
export const { atomInstance: Atom_Transparency, useHook: useStore_Transparency } = createAtomWithHook(100, "Transparency");
|
||||
|
||||
|
||||
export const { atomInstance: Atom_IsOpenedWordFilterList, useHook: useStore_IsOpenedWordFilterList } = createAtomWithHook(false, "IsOpenedWordFilterList");
|
||||
export const { atomInstance: Atom_WordFilterList, useHook: useStore_WordFilterList } = createAtomWithHook(word_filter_list, "WordFilterList");
|
||||
export const { atomInstance: Atom_IsOpenedMicWordFilterList, useHook: useStore_IsOpenedMicWordFilterList } = createAtomWithHook(false, "IsOpenedMicWordFilterList");
|
||||
export const { atomInstance: Atom_MicWordFilterList, useHook: useStore_MicWordFilterList } = createAtomWithHook([], "MicWordFilterList");
|
||||
|
||||
// Transcription
|
||||
export const { atomInstance: Atom_MicRecordTimeout, useHook: useStore_MicRecordTimeout } = createAtomWithHook(0, "MicRecordTimeout");
|
||||
|
||||
Reference in New Issue
Block a user