var path = require("path");
var fs = require("fs");
var currentDir = __dirname;
var sdkPath = path.join(currentDir, "msc.dll");
var sdkTargetPath = sdkPath;
var electron = require("electron");
var app = (electron.remote || electron).app;
console.log("TTSWindowsApi->__dirname="+__dirname);
if (process.arch == "x64") {
    sdkPath = path.join(currentDir, "msc_x64.dll");
}
if (app.getAppPath().indexOf(".asar") >= 0 || app.isPackaged) {
    sdkTargetPath = path.join(path.dirname(app.getPath("exe")), path.basename(sdkPath));
}
if (!fs.existsSync(sdkTargetPath)) {
    fs.writeFileSync(sdkTargetPath, fs.readFileSync(sdkPath));
} else {
    let crypto=require("crypto");
    let sourceHash= crypto.createHash("sha256").update(fs.readFileSync(sdkPath)).digest("hex");
    let targetHash=crypto.createHash("sha256").update(fs.readFileSync(sdkTargetPath)).digest("hex");
    if(targetHash!=sourceHash){
        console.log(`update tts sdk ${sdkTargetPath}`);
        fs.writeFileSync(sdkTargetPath, fs.readFileSync(sdkPath));
    }
}
const { PlayMode } = require("../TTSEnums");
const TTSApi = require("../TTSApi")(sdkTargetPath);
const AudioApi = require("./MCISendStringCmds");
function TTSWindowsApi(options) {
    TTSApi.call(this, AudioApi, options);
}
TTSWindowsApi.prototype = new TTSApi();
TTSWindowsApi.stopPlay = function () {
    AudioApi.stopPlay();
}
module.exports = {
    TTSApi: TTSWindowsApi,
    PlayMode: PlayMode
}
