User Tools

Site Tools


select-option

This is an old revision of the document!


    $.post("/cgi-bin/t.py",
        {
            action: "getvoices"
        })
        .done(function (result, status, xhr) {
            console.dir(result);
            //const obj = JSON.parse(result);
            obj=result;
            console.dir(obj);
            $.each(obj, function (i, item) {
            //    console.dir(i);
                $('#voice').append($('<option>', { 
                    value: item,
                    text : i 
                }));
            });
            //$("#message").html(result)
        })
        .fail(function (xhr, status, error) {
            $("#message").html("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
        });

The result comes back as a object:

t.py code to generate the “result”

    if action == "getvoices":
        voices = text_to_speech.list_voices().get_result()
        v = voices['voices']
        persons = {}
        for x in v:
            name=x['name']
            description = x['description']
            language = x['language']
            if language.startswith('en',0): 
                nam = re.split(":",description)
                persons[nam[0]]=name
        jo = json.dumps(persons)
        print(jo)
select-option.1635175009.txt.gz · Last modified: 2021/10/25 17:16 by admin