Unverified Commit 1d10b2ad authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6409 from DonLakeFlyer/SpeechTranslations

Handle EKF and 4.2m correctly
parents 813ab33c 236b326a
...@@ -73,6 +73,7 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) { ...@@ -73,6 +73,7 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) {
QString match; QString match;
QString newNumber; QString newNumber;
QString result = string; QString result = string;
//-- Look for codified terms //-- Look for codified terms
if(result.contains("ERR ", Qt::CaseInsensitive)) { if(result.contains("ERR ", Qt::CaseInsensitive)) {
result.replace("ERR ", "error ", Qt::CaseInsensitive); result.replace("ERR ", "error ", Qt::CaseInsensitive);
...@@ -118,6 +119,9 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) { ...@@ -118,6 +119,9 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) {
if(result.contains(" ADSB ", Qt::CaseInsensitive)) { if(result.contains(" ADSB ", Qt::CaseInsensitive)) {
result.replace(" ADSB ", " Hey Dee Ess Bee ", Qt::CaseInsensitive); result.replace(" ADSB ", " Hey Dee Ess Bee ", Qt::CaseInsensitive);
} }
if(result.contains(" EKF ", Qt::CaseInsensitive)) {
result.replace(" EKF ", " Eee Kay Eff ", Qt::CaseInsensitive);
}
// Convert negative numbers // Convert negative numbers
QRegularExpression re(QStringLiteral("(-)[0-9]*\\.?[0-9]")); QRegularExpression re(QStringLiteral("(-)[0-9]*\\.?[0-9]"));
...@@ -125,9 +129,18 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) { ...@@ -125,9 +129,18 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) {
while (reMatch.hasMatch()) { while (reMatch.hasMatch()) {
if (!reMatch.captured(1).isNull()) { if (!reMatch.captured(1).isNull()) {
// There is a negative prefix // There is a negative prefix
qDebug() << "negative" << reMatch.captured(1) << reMatch.capturedStart(1) << reMatch.capturedEnd(1);
result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" negative ")); result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" negative "));
qDebug() << result; }
reMatch = re.match(result);
}
// Convert real number with decimal point
re.setPattern(QStringLiteral("([0-9]+)(\\.)([0-9]+)"));
reMatch = re.match(result);
while (reMatch.hasMatch()) {
if (!reMatch.captured(2).isNull()) {
// There is a decimal point
result.replace(reMatch.capturedStart(2), reMatch.capturedEnd(2) - reMatch.capturedStart(2), tr(" point "));
} }
reMatch = re.match(result); reMatch = re.match(result);
} }
...@@ -138,9 +151,7 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) { ...@@ -138,9 +151,7 @@ QString AudioOutput::fixTextMessageForAudio(const QString& string) {
while (reMatch.hasMatch()) { while (reMatch.hasMatch()) {
if (!reMatch.captured(1).isNull()) { if (!reMatch.captured(1).isNull()) {
// There is a meter postfix // There is a meter postfix
qDebug() << "meters" << reMatch.captured(1) << reMatch.capturedStart(1) << reMatch.capturedEnd(1);
result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" meters")); result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" meters"));
qDebug() << result;
} }
reMatch = re.match(result); reMatch = re.match(result);
} }
......
...@@ -18,7 +18,7 @@ AudioOutputTest::AudioOutputTest(void) ...@@ -18,7 +18,7 @@ AudioOutputTest::AudioOutputTest(void)
void AudioOutputTest::_testSpokenReplacements(void) void AudioOutputTest::_testSpokenReplacements(void)
{ {
QString result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10.5m, -10.5m. -10.5 m")); QString result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10.5m, -10.5m. -10.5 m"));
QCOMPARE(result, QStringLiteral(" negative 10.5 meters, negative 10.5 meters. negative 10.5 meters")); QCOMPARE(result, QStringLiteral(" negative 10 point 5 meters, negative 10 point 5 meters. negative 10 point 5 meters"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10m -10 m")); result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10m -10 m"));
QCOMPARE(result, QStringLiteral(" negative 10 meters negative 10 meters")); QCOMPARE(result, QStringLiteral(" negative 10 meters negative 10 meters"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("foo -10m -10 m bar")); result = AudioOutput::fixTextMessageForAudio(QStringLiteral("foo -10m -10 m bar"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment