Exemple #1
0
    public static bool run(strList words)
    {
        string cmd = words.shift();

        if (cmd == "curid")
        {
            return(curId());
        }
        if (cmd == "info")
        {
            return(cmdVoiceDescribe.info(words));
        }
        if (cmd == "list")
        {
            return(cmdVoiceDescribe.list(words));
        }
        if (cmd == "select")
        {
            return(cmdVoiceSelect.run(words));
        }
        if (cmd == "vol")
        {
            return(cmdSpeechVolume(words.getOr(0)));
        }
        if (cmd == "rate")
        {
            return(cmdSpeechRate(words.getOr(0)));
        }
        return(Program.errUnsuppCmd());
    }
Exemple #2
0
    public static bool cmdFlag(strList words)
    {
        string key = words[0];

        if (!flags.ContainsKey(key))
        {
            return(errUnsuppCmd());
        }
        bool val = flags[key];

        if (words.Count >= 2)
        {
            bool upd = cmdFlag_str2bool(words[1]);
            if ((key == "lockdown") && (!upd))
            {
                failIfLockedDown();
            }
            flags[key] = upd;
            val        = upd;
            if (key == "paused")
            {
                if (upd)
                {
                    synth.Pause();
                }
                else
                {
                    synth.Resume();
                }
            }
        }
        Console.WriteLine("ok config_flag {0} {1}", key, (val ? "on" : "off"));
        return(true);
    }
Exemple #3
0
    public static bool decode(strList words)
    {
        string text = Program.textBuf;

        byte[] bytes = {};
        string how;

        while (true)
        {
            how = words.shift();
            if (how == null)
            {
                break;
            }
            if (how == "base64")
            {
                bytes = System.Convert.FromBase64String(text);
                continue;
            }
            if (how == "utf8")
            {
                text = System.Text.Encoding.UTF8.GetString(bytes);
                continue;
            }
            Program.fail("unsupported_decoder " + how);
        }
        return(exact(text, "decoded"));
    }
Exemple #4
0
    public static bool run(strList words)
    {
        string how = words.shift();

        if (how == "arg")
        {
            return(exact(String.Join(" ", words)));
        }
        if (how == "next")
        {
            return(exact(Program.readLn()));
        }
        if (how == "until")
        {
            return(untilMark(words.getOr(0)));
        }
        if (how == "decode")
        {
            return(decode(words));
        }
        if (how == "_debug_dump_json")
        {
            return(dumpTextAsJson());
        }
        return(Program.errUnsuppCmd());
    }
    public static bool list(strList words)
    {
        var voiceIds = new strList(Program.allVoices().Select(v => v.VoiceInfo.Id));

        Console.WriteLine("list {0}", voiceIds.Count);
        Console.WriteLine(String.Join("\n", voiceIds));
        return(true);
    }
Exemple #6
0
    public static bool byId(strList words)
    {
        // unfortunately .SelectVoice() seems to not accept an ID,
        // not even exact names, but only name substrings. Duh.
        List <InstalledVoice> found = Program.findVoicesByIds(words, nMax: 1);

        if (found.Count < 1)
        {
            Program.fail("no_voice");
        }
        return(byNamePart(found[0].VoiceInfo.Name));
    }
Exemple #7
0
 public static bool cmdMust(strList words)
 {
     try {
         return(cmd(words));
     } catch (CodedError err) {
         if (err.fatalRetVal < 1)
         {
             err.fatalRetVal = 7;
         }
         throw err;
     }
 }
Exemple #8
0
    public static bool cmdOutput(strList words)
    {
        string destType = words.shift();

        if (destType == "default")
        {
            failIfLockedDown();
            synth.SetOutputToDefaultAudioDevice();
            Console.WriteLine("ok audio_destination {0}", destType);
            return(true);
        }
        return(errUnsuppCmd());
    }
Exemple #9
0
    public static bool run(strList words)
    {
        string how = words.shift();

        if (how == "id")
        {
            return(byId(words));
        }
        if (how == "namepart")
        {
            return(byNamePart(words.getOr(0)));
        }
        return(Program.errUnsuppCmd());
    }
Exemple #10
0
    public static bool cmdSleep(strList words)
    {
        float  val  = float.Parse(words.shift(), CultureInfo.InvariantCulture);
        string unit = words.shift();

        if (unit != "sec")
        {
            fail("unsupported_time_unit");
        }

        int msec = (int)Math.Ceiling(val * 1.0e3);

        Thread.Sleep(msec);
        Console.WriteLine("ok slept");
        return(true);
    }
    public static bool info(strList words)
    {
        List <VoiceInfo> voices = null;

        if (words.Count < 1)
        {
            voices = new List <VoiceInfo>();
            voices.Add(Program.currentVoice());
        }
        else if (words[0] == "*")
        {
            voices = new List <VoiceInfo>(Program.allVoices(
                                              ).Select(v => v.VoiceInfo));
        }
        else
        {
            voices = new List <VoiceInfo>(Program.findVoicesByIds(words
                                                                  ).Select(v => v.VoiceInfo));
        }
        int nVoices = voices.Count;

        if (nVoices < 1)
        {
            Console.WriteLine("dict 0\n---\n...");
            return(true);
        }
        var dictLengths = new List <int>(nVoices);
        var voiceDescrs = new strList(nVoices);

        foreach (VoiceInfo vi in voices)
        {
            strDict info = new VoiceInfoDict(vi);
            dictLengths.Add(info.Count);
            voiceDescrs.Add(String.Join("\n", info.toColonLines()));
        }
        Console.WriteLine("dict {0}", String.Join(" ", dictLengths));
        foreach (string descr in voiceDescrs)
        {
            Console.WriteLine("---");
            Console.WriteLine(descr);
        }
        Console.WriteLine("...");
        return(true);
    }
    public static bool run(strList words)
    {
        string cmd = words.shift();

        if (cmd == "sync")
        {
            return(sync());
        }
        if (cmd == "start")
        {
            return(start());
        }
        if (cmd == "stop")
        {
            return(stop());
        }
        // pause/resume: toggle the "paused" flag
        return(Program.errUnsuppCmd());
    }
Exemple #13
0
    public static void Main(string[] cliArgs)
    {
        flags = new Dictionary <string, bool>()
        {
            { "echo", false },
            { "lockdown", false },
            { "paused", false },
        };

        readLnInputQ = new strList(cliArgs);
        if (readLnInputQ.Count == 0)
        {
            cmdInteractive();
        }
        synth.SetOutputToDefaultAudioDevice();
        int retVal = 0;

        while (true)
        {
            try {
                cmd();
            } catch (CodedError err) {
                string code = err.errorCode;
                if (err.fatalRetVal == 0)
                {
                    break;
                }
                Console.Error.WriteLine("err {0}", code);
                if (err.fatalRetVal > 0)
                {
                    retVal = err.fatalRetVal;
                    break;
                }
            }
        }

        synth.Dispose();
        // Probably implicit, but serves as a reminder for me about how
        // to exit non-zero.      – mk
        Console.WriteLine("hint quit rv={0}", retVal);
        Environment.Exit(retVal);
    }
Exemple #14
0
    public static List <InstalledVoice> findVoicesByIds(
        strList voiceIds,
        int nMax = -1
        )
    {
        List <InstalledVoice> all = allVoices();
        var collect = new List <InstalledVoice>();

        foreach (string wantId in voiceIds)
        {
            int found = all.FindIndex(v => v.VoiceInfo.Id == wantId);
            if (found < 0)
            {
                continue;
            }
            collect.Add(all[found]);
            if ((0 <= nMax) && (nMax <= collect.Count))
            {
                break;
            }
        }
        return(collect);
    }
Exemple #15
0
    public static bool cmd(strList words = null)
    {
        if (words == null)
        {
            string ln = readLn();
            if (ln == null)
            {
                return(die("quit"));
            }
            words = strList.splitWords(ln);
        }
        if (words.Count < 1)
        {
            return(true);
        }
        string cmd = words.shift();

        if (cmd == "#")
        {
            return(true);
        }
        if (cmd == "must")
        {
            return(cmdMust(words));
        }
        if (cmd == "quit")
        {
            return(die("quit"));
        }
        if (cmd == "flag")
        {
            return(cmdFlag(words));
        }
        if (cmd == "interactive")
        {
            return(cmdInteractive());
        }
        if (cmd == "voice")
        {
            return(cmdVoice.run(words));
        }
        if (cmd == "vol")
        {
            return(cmdMasterVolume(words.getOr(0)));
        }
        if (cmd == "audio_output")
        {
            return(cmdOutput(words));
        }
        if (cmd == "set_text")
        {
            return(cmdSetTextBuf.run(words));
        }
        if (cmd == "speak")
        {
            return(cmdSpeak.run(words));
        }
        if (cmd == "speak_sync")
        {
            return(cmdSpeak.sync());
        }                                              // legacy v1.0.1 compat
        if (cmd == "sleep")
        {
            return(cmdSleep(words));
        }
        return(errUnsuppCmd());
    }