Exemplo n.º 1
0
bool ModelManager::storeActiveModel(const QDateTime& changedTime, qint32 sampleRate, const QByteArray& container)
{
  KConfig config( KStandardDirs::locateLocal("appdata", "model/activemodelrc"), KConfig::SimpleConfig );
  KConfigGroup cGroup(&config, "");
  cGroup.writeEntry("Date", changedTime);
  config.sync();

  SpeechModelManagementConfiguration::setModelSampleRate(sampleRate);

  QFile containerFile(KStandardDirs::locateLocal("appdata", "model/active.sbm"));

  if (!containerFile.open(QIODevice::WriteOnly))
    return false;

  containerFile.write(container);
  containerFile.close();

  bool success = false;
  QDateTime creationDate;
  QString name;
  ModelMetadata *data = metaDataFromBuffer(container);
  if (data) {
    success = updateBlacklistedTranscriptions(data);
    creationDate = data->dateTime();
    name = data->name();
    delete data;
  }
  emit activeModelStored(creationDate, name);
  return success;
}
Exemplo n.º 2
0
bool ModelManager::storeBaseModel(const QDateTime& changedTime, int baseModelType, const QByteArray& container)
{
  KConfig config( KStandardDirs::locateLocal("appdata", "model/modelsrcrc"), KConfig::SimpleConfig );
  KConfigGroup cGroup(&config, "");
  cGroup.writeEntry("BaseModelDate", changedTime);
  cGroup.writeEntry("BaseModelType", baseModelType);
  config.sync();

  QString repoPath = KStandardDirs::locateLocal("appdata", "model/base/srv" + changedTime.toString(Qt::ISODate) + ".sbm");
  //store both as selected base model and in the local repository
  foreach (const QString& path, QStringList() << KStandardDirs::locateLocal("appdata", "model/basemodel.sbm")
                                                    << repoPath) {
    QFile containerFile(path);
    if (!containerFile.open(QIODevice::WriteOnly))
      return false;
    containerFile.write(container);
    containerFile.close();
  }
  setBaseModel(repoPath, baseModelType);

  QDateTime creationDate;
  QString name;
  ModelMetadata *data = metaDataFromBuffer(container);
  if (data) {
    name = data->name();
    creationDate = data->dateTime();
    delete data;
  }
  announceBaseModel(name, baseModelType, creationDate);
  return true;
}
Exemplo n.º 3
0
bool SphinxControl::initializeRecognition(const QString &modelPath)
{
  kDebug() << "Initializing to " << modelPath << m_lastModel;
  if (modelPath != m_lastModel) { //already initialized / tried to initialize with this exact model
    m_lastModel = modelPath;
    kDebug() << "Initializing";
    uninitialize();
    m_startRequests = 0;

    QString path = KStandardDirs::locateLocal("tmp", "/simond/"+username+"/sphinx/");
    if(!QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst).isEmpty())
    {
      kDebug() << "Removing old data from working dir";
      FileUtils::removeDirRecursive(path);
      path = KStandardDirs::locateLocal("tmp", "/simond/"+username+"/sphinx/");
    }

    kDebug() << "Unpacking model to working dir";
    if (!FileUtils::unpackAll(modelPath, path))
    {
      return false;
    }

    QFile metadataFile(path+QLatin1String("metadata.xml"));
    if(!metadataFile.open(QIODevice::ReadOnly))
    {
      emit recognitionError(i18n("Failed to read metadata from \"%1\"", path+QLatin1String("metadata.xml")),
                            getBuildLog());
      return NULL;
    }
    ModelMetadata metadata;
    QDomDocument DomDocument;
    DomDocument.setContent(&metadataFile);
    metadata.deserializeXml(DomDocument.documentElement());

    metadataFile.close();

    modelName = metadata.name();
  }
  kDebug() << "Emitting recognition ready";
  emit recognitionReady();
  return true;
}
Exemplo n.º 4
0
        MetadataNamePropertyWrapper(
                OSSIA::Node& parent,
                ModelMetadata& arg_metadata,
                QObject* context
                ):
            metadata{arg_metadata}
        {
            node = *parent.emplace(
                       parent.children().end(),
                       arg_metadata.name().toStdString());

            /*
            m_callbackIt =
                    node->addCallback(
                        [=] (const OSSIA::Node& node, const std::string& name, OSSIA::NodeChange t) {
                if(t == OSSIA::NodeChange::RENAMED)
                {
                    auto str = QString::fromStdString(node.getName());
                    if(str != metadata.name())
                        metadata.setName(str);
                }
            });
            */

            auto setNameFun = [=] (const QString& newName_qstring) {
                auto newName = newName_qstring.toStdString();
                auto curName = node->getName();

                if(curName != newName)
                {
                    node->setName(newName);
                    auto real_newName = node->getName();

                    if(real_newName != newName)
                    {
                        metadata.setName(QString::fromStdString(real_newName));
                    }
                }
            };

            QObject::connect(
                        &metadata, &ModelMetadata::nameChanged,
                        context, setNameFun,
                        Qt::QueuedConnection);

            setNameFun(metadata.name());
        }