Newer
Older
CasicIrisIdentify / utils / SpeakerUtil.cpp
#include "SpeakerUtil.h"

SpeakerUtil::SpeakerUtil(QObject *parent) : QObject(parent)
{
    tts = new QTextToSpeech(parent);
    tts->setLocale(QLocale::Chinese);
    tts->setRate(0.0);
    tts->setPitch(1.0);
    tts->setVolume(1.0);

    // 循环播放
    effect.setLoopCount(QSoundEffect::Null);
    // 设置音量,0-1
    effect.setVolume(1.0f);
}

void SpeakerUtil::speak(QString content)
{
    if (tts->state() == QTextToSpeech::Ready && tts->state() != QTextToSpeech::Speaking)
    {
        tts->say(content);
    }
}

void SpeakerUtil::sayIdentifySuccessZhCn()
{
    effect.setSource(QUrl::fromLocalFile("wav/recSuccess.wav"));
    effect.play();
}

void SpeakerUtil::sayIdentifyFailureZhCn()
{
    effect.setSource(QUrl::fromLocalFile("wav/recFailureRetry.wav"));
    effect.play();
}