1- import React , { useCallback , useEffect , useMemo } from "react" ;
2- import { AveRenderer , Grid , Window , getAppContext , IIconResource , IWindowComponentProps , Button , CheckBox , ICheckBoxComponentProps } from "ave-react" ;
1+ import React , { useCallback , useEffect , useMemo , useState } from "react" ;
2+ import { AveRenderer , Grid , Window , getAppContext , IIconResource , IWindowComponentProps , Button , CheckBox , ICheckBoxComponentProps , ScrollBar , Label , IScrollBarComponentProps } from "ave-react" ;
33import { App , ThemePredefined_Dark , CheckValue } from "ave-ui" ;
44import { VoskAsrEngine } from "./asr" ;
55import { HelsinkiNlpEngine } from "./nlp" ;
66import { containerLayout , controlLayout } from "./layout" ;
77import { iconResource } from "./resource" ;
8- import { onMeasure , onTranslate , shadowRelated } from "./shadow" ;
8+ import { logger , onMeasure , onTranslate , shadowRelated } from "./shadow" ;
99import { getAsrConfig , getNlpConfig } from "./config" ;
1010
1111function onInit ( app : App ) {
@@ -20,6 +20,14 @@ function initTheme() {
2020 themeDark . SetStyle ( themeImage , 0 ) ;
2121}
2222
23+ enum ButtonText {
24+ Measure = "设置字幕区" ,
25+ Recognize = "语音识别" ,
26+ SetTopMost = "字幕置顶" ,
27+ SubtitleEn = "英文字幕" ,
28+ SubtitleZh = "中文字幕" ,
29+ }
30+
2331export function Echo ( ) {
2432 const asrEngine = useMemo (
2533 ( ) =>
@@ -57,29 +65,39 @@ export function Echo() {
5765 } , [ ] ) ;
5866
5967 const onSetRecognize = useCallback < ICheckBoxComponentProps [ "onCheck" ] > ( ( sender ) => {
68+ shadowRelated . subtitleQueue = [ ] ;
69+
6070 let shouldRecognize = false ;
6171
6272 const checkValue = sender . GetValue ( ) ;
6373 if ( checkValue === CheckValue . Unchecked ) {
6474 shouldRecognize = false ;
75+ logger . end ( ) ;
6576 } else if ( checkValue === CheckValue . Checked ) {
6677 shouldRecognize = true ;
78+ logger . start ( ) ;
6779 }
6880
6981 shadowRelated . shouldRecognize = shouldRecognize ;
7082 } , [ ] ) ;
7183
72- const onSetPunct = useCallback < ICheckBoxComponentProps [ "onCheck" ] > ( ( sender ) => {
73- let shouldResotrePunct = false ;
74-
84+ const onSetDisplaySubtitle = useCallback < ICheckBoxComponentProps [ "onCheck" ] > ( ( sender ) => {
7585 const checkValue = sender . GetValue ( ) ;
76- if ( checkValue === CheckValue . Unchecked ) {
77- shouldResotrePunct = false ;
78- } else if ( checkValue === CheckValue . Checked ) {
79- shouldResotrePunct = true ;
86+ const text = sender . GetText ( ) ;
87+ const isChecked = checkValue === CheckValue . Checked ;
88+ if ( text === ButtonText . SubtitleEn ) {
89+ shadowRelated . subtitleConfig . en = isChecked ;
90+ } else if ( text === ButtonText . SubtitleZh ) {
91+ shadowRelated . subtitleConfig . zh = isChecked ;
8092 }
93+ shadowRelated . onUpdateTranslationConfig ( ) ;
94+ } , [ ] ) ;
8195
82- shadowRelated . shouldResotrePunct = shouldResotrePunct ;
96+ const [ fontSize , setFontSize ] = useState ( 24 ) ;
97+ const onSetFontSize = useCallback < IScrollBarComponentProps [ "onScrolling" ] > ( ( sender ) => {
98+ const fontSize = sender . GetValue ( ) ;
99+ shadowRelated . onUpdateFontSize ( fontSize ) ;
100+ setFontSize ( fontSize ) ;
83101 } , [ ] ) ;
84102
85103 useEffect ( ( ) => {
@@ -94,16 +112,28 @@ export function Echo() {
94112 < Grid style = { { layout : containerLayout } } >
95113 < Grid style = { { area : containerLayout . areas . control , layout : controlLayout } } >
96114 < Grid style = { { area : controlLayout . areas . measure } } >
97- < Button text = "设置字幕区" iconInfo = { { name : "measure" , size : 16 } } onClick = { onMeasure } > </ Button >
115+ < Button text = { ButtonText . Measure } iconInfo = { { name : "measure" , size : 16 } } onClick = { onMeasure } > </ Button >
98116 </ Grid >
99117 < Grid style = { { area : controlLayout . areas . recognize } } >
100- < CheckBox text = "语音识别" value = { CheckValue . Unchecked } onCheck = { onSetRecognize } > </ CheckBox >
101- </ Grid >
102- < Grid style = { { area : controlLayout . areas . punct } } >
103- < CheckBox text = "标点恢复" value = { CheckValue . Unchecked } onCheck = { onSetPunct } > </ CheckBox >
118+ < CheckBox text = { ButtonText . Recognize } value = { CheckValue . Unchecked } onCheck = { onSetRecognize } > </ CheckBox >
104119 </ Grid >
105120 < Grid style = { { area : controlLayout . areas . topmost } } >
106- < CheckBox text = "字幕置顶" value = { CheckValue . Checked } onCheck = { onSetTopMost } > </ CheckBox >
121+ < CheckBox text = { ButtonText . SetTopMost } value = { CheckValue . Checked } onCheck = { onSetTopMost } > </ CheckBox >
122+ </ Grid >
123+ < Grid style = { { area : controlLayout . areas . en } } >
124+ < CheckBox text = { ButtonText . SubtitleEn } value = { CheckValue . Checked } onCheck = { onSetDisplaySubtitle } > </ CheckBox >
125+ </ Grid >
126+ < Grid style = { { area : controlLayout . areas . zh } } >
127+ < CheckBox text = { ButtonText . SubtitleZh } value = { CheckValue . Checked } onCheck = { onSetDisplaySubtitle } > </ CheckBox >
128+ </ Grid >
129+ < Grid style = { { area : controlLayout . areas . fontSizeLabel } } >
130+ < Label text = "字体大小" > </ Label >
131+ </ Grid >
132+ < Grid style = { { area : controlLayout . areas . fontSize , margin : "10dpx 0 10dpx 0" } } >
133+ < ScrollBar min = { 10 } max = { 50 } value = { 24 } /** default value */ onScrolling = { onSetFontSize } > </ ScrollBar >
134+ </ Grid >
135+ < Grid style = { { area : controlLayout . areas . fontSizeValue } } >
136+ < Label text = { `${ fontSize } ` } > </ Label >
107137 </ Grid >
108138 </ Grid >
109139 </ Grid >
0 commit comments