Commit ae80335f authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

wip: first version of working text clip analysis

parent c76ae6b1
Pipeline #50106 passed with stage
in 10 minutes and 24 seconds
......@@ -34,7 +34,7 @@ def transcribe():
results = []
subs = []
while True:
data = process.stdout.read(4000)
data = process.stdout.read(2000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
......
......@@ -138,31 +138,50 @@ void TextBasedEdit::slotProcessSpeech()
QString saveData = QString::fromUtf8(m_speechJob->readAll());
//saveData.replace(QStringLiteral("\\\""), QStringLiteral("\""));
qDebug()<<"=== GOT DATA:\n"<<saveData;
//QJsonDocument loadDoc(QJsonDocument::fromJson(saveData.toUtf8().constData()));
QJsonParseError error;
auto loadDoc = QJsonDocument::fromJson(saveData.toUtf8(), &error);
qDebug()<<"===JSON ERROR: "<<error.errorString();
int ix = 0;
QVector <int> indexes;
while (ix > -1) {
ix = saveData.indexOf(QStringLiteral("{\n \"result\""), ix);
if (ix > -1) {
indexes << ix;
ix++;
}
}
qDebug()<<"Found res: "<<indexes;
QString chunk;
while (!indexes.isEmpty()) {
int first = indexes.takeFirst();
if (indexes.isEmpty()) {
chunk = saveData.mid(first);
} else {
chunk = saveData.mid(first, indexes.at(0) - first);
}
qDebug()<<"cut: "<<saveData;
QJsonParseError error;
auto loadDoc = QJsonDocument::fromJson(chunk.toUtf8(), &error);
qDebug()<<"===JSON ERROR: "<<error.errorString();
if (loadDoc.isArray()) {
qDebug()<<"==== ITEM IS ARRAY";
QJsonArray array = loadDoc.array();
for (int i = 0; i < array.size(); i++) {
QJsonValue val = array.at(i);
qDebug()<<"==== FOUND KEYS: "<<val.toObject().keys();
if (val.isObject() && val.toObject().keys().contains("text")) {
textEdit->append(val.toObject().value("text").toString());
if (loadDoc.isArray()) {
qDebug()<<"==== ITEM IS ARRAY";
QJsonArray array = loadDoc.array();
for (int i = 0; i < array.size(); i++) {
QJsonValue val = array.at(i);
qDebug()<<"==== FOUND KEYS: "<<val.toObject().keys();
if (val.isObject() && val.toObject().keys().contains("text")) {
textEdit->append(val.toObject().value("text").toString());
}
}
} else if (loadDoc.isObject()) {
QJsonObject obj = loadDoc.object();
qDebug()<<"==== ITEM IS OBJECT";
if (!obj.isEmpty()) {
textEdit->append(obj["text"].toString());
}
} else if (loadDoc.isEmpty()) {
qDebug()<<"==== EMPTY OBJEC DOC";
}
} else if (loadDoc.isObject()) {
QJsonObject obj = loadDoc.object();
qDebug()<<"==== ITEM IS OBJECT";
if (!obj.isEmpty()) {
textEdit->append(obj["text"].toString());
}
} else if (loadDoc.isEmpty()) {
qDebug()<<"==== EMPTY OBJEC DOC";
}
}
void TextBasedEdit::slotParseDictionaries()
......
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