mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-17 08:10:22 -07:00
GetSrcLang, GetDstLang, SetSrcLang, SetDstLang, SwapLang are reusable functions from translator to translator. So make Language struct. GetEngineName is also a reusable function. So make EngineName struct. Finally, let Translator to inherit those functions in these three (Language, TTSLock, EngineName) structs. No need to write the duplicated functions for each Translator.
36 lines
489 B
Go
36 lines
489 B
Go
package core
|
|
|
|
type TTSLock struct {
|
|
stop bool
|
|
threadCount int8
|
|
}
|
|
|
|
func NewTTSLock() *TTSLock {
|
|
return &TTSLock{
|
|
stop: true,
|
|
threadCount: 0,
|
|
}
|
|
}
|
|
|
|
func (l *TTSLock) LockAvailable() bool {
|
|
return l.stop && l.threadCount == 0
|
|
}
|
|
|
|
func (l *TTSLock) AcquireLock() {
|
|
l.stop = false
|
|
l.threadCount++
|
|
}
|
|
|
|
func (l *TTSLock) IsStopped() bool {
|
|
return l.stop
|
|
}
|
|
|
|
func (l *TTSLock) StopTTS() {
|
|
l.stop = true
|
|
}
|
|
|
|
func (l *TTSLock) ReleaseLock() {
|
|
l.stop = true
|
|
l.threadCount--
|
|
}
|