From 6bb360c464fa0a5fe571afab21b9edd3e863f630 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 24 May 2023 16:20:12 +0200 Subject: 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 --- tests/auto/qtexttospeech/tst_qtexttospeech.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') 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 #include #include +#include #include #include #include @@ -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(), 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) -- cgit v1.2.3