summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-24 16:20:12 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-28 13:08:27 +0000
commit6bb360c464fa0a5fe571afab21b9edd3e863f630 (patch)
treea435deb8cd3105f3d0b719b5eadacdaea01f020a /tests
parentc1afe1600d37c5533904da7e2862e87fa05464e6 (diff)
API review: Allow synthesize callbacks that take a QAudioBuffer
Formally, QAudioBuffer is the right type for carrying audio data, but it's hardly used in Qt Multimedia itself, and not very practical to use for writing the received PCM data to a file or to stream it out to a QAudioSink (which operators on a QIODevice, e.g. with a byte array). Nevertheless, allow a callback to take a QAudioBuffer instead of QAudioFormat and QByteArray, as the QAudioBuffer facilities might be useful for some use cases. Change-Id: I260a4cf6cf91f57356373f4ef9cf248927159b40 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtexttospeech/tst_qtexttospeech.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp
index 701effe..317c683 100644
--- a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp
+++ b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp
@@ -8,6 +8,7 @@
#include <QMediaDevices>
#include <QAudioFormat>
#include <QAudioDevice>
+#include <QAudioBuffer>
#include <QOperatingSystemVersion>
#include <QRegularExpression>
#include <qttexttospeech-config.h>
@@ -1063,6 +1064,16 @@ void tst_QTextToSpeech::synthesizeCallback()
QTRY_COMPARE(tts.state(), QTextToSpeech::Ready);
QCOMPARE(processor.m_allBytes, QByteArray());
processor.reset();
+
+ // Taking QAudioBuffer
+ tts.synthesize(text, [&processor](const QAudioBuffer &buffer) {
+ processor.m_format = buffer.format();
+ processor.m_allBytes += QByteArrayView(buffer.data<uchar>(), buffer.byteCount());
+ });
+ QTRY_COMPARE(processor.m_format, expectedFormat);
+ QTRY_COMPARE(tts.state(), QTextToSpeech::Ready);
+ QCOMPARE(processor.m_allBytes, expectedBytes);
+ processor.reset();
}
QTEST_MAIN(tst_QTextToSpeech)