<commit_before>'use strict';

import request from 'request';
import {spawn} from 'child_process';
import temp from 'temp';
import fs from 'fs';
temp.track();

function talk(position, language = 'de', cb) {
    if ('function' === typeof language) {
        cb = language;
        language = 'de';
    }
    let options = {
        url: 'https://translate.google.com/translate_tts',
        qs: {
            ie: 'UTF-8',
            q: position.label,
            tl: language,
            total: 1,
            idx: 0,
            textlen: position.label.length,
            tk: '162937|286006',
            client: 't'
        },
        headers: {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
            'Referer': 'https://translate.google.com/'
        }
    };

    temp.open({suffix: '.mp3'}, (err, info) => {
        if (err) {
            throw err;
        }
        request(options).pipe(fs.createWriteStream(info.path))
            .on('close', () => {
                let proc = spawn('mpg123', [info.path]);
                proc.on('close', function () {
                    temp.cleanup();
                    cb();
                });
            });
    });
}

export default talk;<commit_msg>use predefined files for audio output<commit_after>'use strict';

import request from 'request';
import {spawn} from 'child_process';
import fs from 'fs';
import settings from './settings';
import path from 'path';

let dir = settings.get('talk').audioDir;

function talk(position, language = 'de', cb) {
    if ('function' === typeof language) {
        cb = language;
        language = 'de';
    }

    let audioFile = path.join(dir, position.label + '.mp3');

    let stat = fs.statSync(audioFile);
    if (stat.isFile() && stat.size) {
        let proc = spawn('mpg123', [audioFile]);
        proc.on('close', function () {
            cb();
        });
    } else {
        cb();
    }
}

export default talk;
{'fraction_non_alphanumeric': 0.15517241379310345, 'fraction_numerical': 0.02413793103448276, 'mean_word_length': 1.9139167862266857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5648010', 'n_tokens_mistral': 649, 'n_tokens_neox': 606, 'n_words': 156}