mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-17 23:04:06 +00:00
fix: pronounce the first dictionary audio if availabe (#981)
* fix: pronounce the first dictionary audio if availabe fix #978 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5f2a1981c0
commit
b3d9d79816
|
@ -638,6 +638,10 @@ void ArticleRequest::bodyFinished()
|
||||||
activeDicts[ activeDicts.size() - bodyRequests.size() ];
|
activeDicts[ activeDicts.size() - bodyRequests.size() ];
|
||||||
|
|
||||||
string dictId = activeDict->getId();
|
string dictId = activeDict->getId();
|
||||||
|
|
||||||
|
//signal finished dictionray for pronounciation
|
||||||
|
GlobalBroadcaster::instance()->pronounce_engine.finishDictionary( dictId );
|
||||||
|
|
||||||
dictIds << QString::fromStdString(dictId);
|
dictIds << QString::fromStdString(dictId);
|
||||||
string head;
|
string head;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ std::string addAudioLink( std::string const & url,
|
||||||
if ( url.empty() || url.length() < 2 )
|
if ( url.empty() || url.length() < 2 )
|
||||||
return {};
|
return {};
|
||||||
GlobalBroadcaster::instance()->pronounce_engine.sendAudio(
|
GlobalBroadcaster::instance()->pronounce_engine.sendAudio(
|
||||||
|
dictionaryId,
|
||||||
QString::fromStdString( url.substr( 1, url.length() - 2 ) ) );
|
QString::fromStdString( url.substr( 1, url.length() - 2 ) ) );
|
||||||
|
|
||||||
return std::string( "<script type=\"text/javascript\">" + makeAudioLinkScript( url, dictionaryId ) + "</script>" );
|
return std::string( "<script type=\"text/javascript\">" + makeAudioLinkScript( url, dictionaryId ) + "</script>" );
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "pronounceengine.hh"
|
#include "pronounceengine.hh"
|
||||||
|
#include <QMutexLocker>
|
||||||
|
|
||||||
PronounceEngine::PronounceEngine( QObject * parent ):
|
PronounceEngine::PronounceEngine( QObject * parent ):
|
||||||
QObject{ parent }
|
QObject{ parent }
|
||||||
|
@ -10,13 +11,34 @@ void PronounceEngine::reset()
|
||||||
{
|
{
|
||||||
QMutexLocker _( &mutex );
|
QMutexLocker _( &mutex );
|
||||||
state = PronounceState::AVAILABLE;
|
state = PronounceState::AVAILABLE;
|
||||||
|
|
||||||
|
dictAudioMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PronounceEngine::sendAudio( QString audioLink )
|
|
||||||
|
void PronounceEngine::sendAudio( std::string dictId, QString audioLink )
|
||||||
{
|
{
|
||||||
QMutexLocker _( &mutex );
|
|
||||||
if ( state == PronounceState::OCCUPIED )
|
if ( state == PronounceState::OCCUPIED )
|
||||||
return;
|
return;
|
||||||
state = PronounceState::OCCUPIED;
|
|
||||||
emit emitAudio( audioLink );
|
QMutexLocker _( &mutex );
|
||||||
|
|
||||||
|
dictAudioMap.operator[]( dictId ).push_back( audioLink );
|
||||||
|
}
|
||||||
|
|
||||||
|
void PronounceEngine::finishDictionary( std::string dictId )
|
||||||
|
{
|
||||||
|
if ( state == PronounceState::OCCUPIED )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( dictAudioMap.contains( dictId ) ) {
|
||||||
|
{
|
||||||
|
//limit the mutex scope.
|
||||||
|
QMutexLocker _( &mutex );
|
||||||
|
if ( state == PronounceState::OCCUPIED )
|
||||||
|
return;
|
||||||
|
state = PronounceState::OCCUPIED;
|
||||||
|
}
|
||||||
|
emit emitAudio( dictAudioMap[ dictId ].first() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define PRONOUNCEENGINE_HH
|
#define PRONOUNCEENGINE_HH
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMutexLocker>
|
#include <QMap>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,11 +17,13 @@ class PronounceEngine: public QObject
|
||||||
PronounceState state = PronounceState::AVAILABLE;
|
PronounceState state = PronounceState::AVAILABLE;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
|
QMap< std::string, QList< QString > > dictAudioMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PronounceEngine( QObject * parent = nullptr );
|
explicit PronounceEngine( QObject * parent = nullptr );
|
||||||
void reset();
|
void reset();
|
||||||
void sendAudio( QString audioLink );
|
void sendAudio( std::string dictId, QString audioLink );
|
||||||
|
void finishDictionary( std::string dictId );
|
||||||
signals:
|
signals:
|
||||||
void emitAudio( QString audioLink );
|
void emitAudio( QString audioLink );
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue