<commit_before>/* jshint -W097 */
/* jshint strict: false */
/* jslint node: true */
'use strict';
const utils         = require('@iobroker/adapter-core'); // Get common adapter utils
const engines       = require('./admin/engines.js');
const Text2Speech   = require('./lib/text2speech');
const Speech2Device = require('./lib/speech2device');
const adapterName   = require('./package.json').name.split('.').pop();

const sayitOptions  = engines.sayitOptions;
const libs          = {
    fs:     require('fs'),
    path:   require('path')
};

let dataDir = libs.path.normalize(utils.controllerDir + '/' + require(utils.controllerDir + '/lib/tools').getDefaultDataDir() + '/sayit');

process.on('SIGINT', stop);

let processMessageTimeout;
let sayFinishedTimeout;
let cacheTimeout;

let adapter;

function startAdapter(options) {
    options = options || {};
    Object.assign(options, {name: adapterName, unload: stop});
    adapter = new utils.Adapter(options);

    adapter.on('stateChange', (id, state) => {
        if (state && !state.ack) {
            if (id === adapter.namespace + '.tts.clearQueue') {
                if (list.length > 1) {
                    list.splice(1);
                    adapter.setState('tts.clearQueue', false, true);
                }
            } else if (id === adapter.namespace + '.tts.volume') {
                if (adapter.config.type === 'system') {
                    speech2device.sayItSystemVolume(state.val);
                } else {
                    options.sayLastVolume = state.val;
                }
            } else if (id === adapter.namespace + '.tts.text') {
                if (typeof state.val !== 'string') {
                    if (state.val === null || state.val === undefined || state.val === '') {
                        adapter.log.warn('Cannot cache empty text');
                        return;
                    }
                    state.val = state.val.toString();
                }

                sayIt(state.val);
            } else if (id === adapter.namespace + '.tts.cachetext') {

                if (typeof state.val !== 'string') {
                    if (state.val === null || state.val === undefined || state.val === '') {
                        adapter.log.warn('Cannot cache empty text');
                        return;
                    }
                    state.val = state.val.toString();
                }

                cacheIt(state.val);
            }
        }
    });

    adapter.on('ready', main);

    adapter.on('message', obj => processMessage(obj));

    try {
        // create directory
        if (!libs.fs.existsSync(dataDir)) {
            libs.fs.mkdirSync(dataDir);
        }
    } catch (err) {
        adapter.log.error('Could not create Storage directory: ' + err);
        dataDir = __dirname;
    }

    MP3FILE = adapter.config.dataDir + '/' + adapter.namespace + '.say.' + fileExt;

    return adapter;<commit_msg>* try to create a separate directory in iobroker-data<commit_after>/* jshint -W097 */
/* jshint strict: false */
/* jslint node: true */
'use strict';
const utils         = require('@iobroker/adapter-core'); // Get common adapter utils
const engines       = require('./admin/engines.js');
const Text2Speech   = require('./lib/text2speech');
const Speech2Device = require('./lib/speech2device');
const adapterName   = require('./package.json').name.split('.').pop();

const sayitOptions  = engines.sayitOptions;
const libs          = {
    fs:     require('fs'),
    path:   require('path')
};

let dataDir = libs.path.normalize(utils.controllerDir + '/' + require(utils.controllerDir + '/lib/tools').getDefaultDataDir() + '/sayit');

process.on('SIGINT', stop);

let processMessageTimeout;
let sayFinishedTimeout;
let cacheTimeout;

let adapter;

function startAdapter(options) {
    options = options || {};
    Object.assign(options, {name: adapterName, unload: stop});
    adapter = new utils.Adapter(options);

    adapter.on('stateChange', (id, state) => {
        if (state && !state.ack) {
            if (id === adapter.namespace + '.tts.clearQueue') {
                if (list.length > 1) {
                    list.splice(1);
                    adapter.setState('tts.clearQueue', false, true);
                }
            } else if (id === adapter.namespace + '.tts.volume') {
                if (adapter.config.type === 'system') {
                    speech2device.sayItSystemVolume(state.val);
                } else {
                    options.sayLastVolume = state.val;
                }
            } else if (id === adapter.namespace + '.tts.text') {
                if (typeof state.val !== 'string') {
                    if (state.val === null || state.val === undefined || state.val === '') {
                        adapter.log.warn('Cannot cache empty text');
                        return;
                    }
                    state.val = state.val.toString();
                }

                sayIt(state.val);
            } else if (id === adapter.namespace + '.tts.cachetext') {

                if (typeof state.val !== 'string') {
                    if (state.val === null || state.val === undefined || state.val === '') {
                        adapter.log.warn('Cannot cache empty text');
                        return;
                    }
                    state.val = state.val.toString();
                }

                cacheIt(state.val);
            }
        }
    });

    adapter.on('ready', main);

    adapter.on('message', obj => processMessage(obj));

    try {
        // create directory
        if (!libs.fs.existsSync(dataDir)) {
            libs.fs.mkdirSync(dataDir);
        }
    } catch (err) {
        adapter.log.error('Could not create Storage directory: ' + err);
        dataDir = __dirname;
    }

    MP3FILE = dataDir + '/' + adapter.namespace + '.say.' + fileExt;

    return adapter;
{'fraction_non_alphanumeric': 0.15017757483510907, 'fraction_numerical': 0.0037206155927617113, 'mean_word_length': 1.745589600742804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '427418', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1582, 'n_words': 347}