2023-07-13 06:49:41 +00:00
|
|
|
#include "pronounceengine.hh"
|
2023-07-17 23:57:02 +00:00
|
|
|
#include <QMutexLocker>
|
2023-07-25 15:55:41 +00:00
|
|
|
#include "common/utils.hh"
|
|
|
|
#include <QUrl>
|
2023-07-13 06:49:41 +00:00
|
|
|
|
|
|
|
PronounceEngine::PronounceEngine( QObject * parent ):
|
|
|
|
QObject{ parent }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PronounceEngine::reset()
|
|
|
|
{
|
|
|
|
QMutexLocker _( &mutex );
|
|
|
|
state = PronounceState::AVAILABLE;
|
2023-07-17 23:57:02 +00:00
|
|
|
|
|
|
|
dictAudioMap.clear();
|
2023-07-13 06:49:41 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 23:57:02 +00:00
|
|
|
|
|
|
|
void PronounceEngine::sendAudio( std::string dictId, QString audioLink )
|
2023-07-13 06:49:41 +00:00
|
|
|
{
|
2023-07-17 23:57:02 +00:00
|
|
|
if ( state == PronounceState::OCCUPIED ) {
|
|
|
|
return;
|
2024-10-10 07:13:23 +00:00
|
|
|
}
|
2023-07-17 23:57:02 +00:00
|
|
|
|
2023-07-25 15:55:41 +00:00
|
|
|
if ( !Utils::Url::isAudioUrl( QUrl( audioLink ) ) ) {
|
|
|
|
return;
|
2024-10-10 07:13:23 +00:00
|
|
|
}
|
2023-07-25 15:55:41 +00:00
|
|
|
|
2023-07-13 06:49:41 +00:00
|
|
|
QMutexLocker _( &mutex );
|
2023-07-17 23:57:02 +00:00
|
|
|
|
|
|
|
dictAudioMap.operator[]( dictId ).push_back( audioLink );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PronounceEngine::finishDictionary( std::string dictId )
|
|
|
|
{
|
2023-07-13 06:49:41 +00:00
|
|
|
if ( state == PronounceState::OCCUPIED ) {
|
|
|
|
return;
|
2024-10-10 07:13:23 +00:00
|
|
|
}
|
2023-07-17 23:57:02 +00:00
|
|
|
|
|
|
|
if ( dictAudioMap.contains( dictId ) ) {
|
|
|
|
{
|
|
|
|
//limit the mutex scope.
|
|
|
|
QMutexLocker _( &mutex );
|
|
|
|
if ( state == PronounceState::OCCUPIED ) {
|
|
|
|
return;
|
2024-10-10 07:13:23 +00:00
|
|
|
}
|
2023-07-17 23:57:02 +00:00
|
|
|
state = PronounceState::OCCUPIED;
|
|
|
|
}
|
|
|
|
emit emitAudio( dictAudioMap[ dictId ].first() );
|
|
|
|
}
|
2023-07-13 06:49:41 +00:00
|
|
|
}
|