Domanda per applecript con drago Dictate

0

Voglio creare un programma che prenderà la domanda che gli chiedo, inserendolo in WolframAlpha, prendi la risposta, convertila in testo e pronuncia il testo.

    set defaultAnswer to ""
set cancelButton to "Cancel"
set buttonResearch to “ReSearch”

display dialog "Query: " default answer defaultAnswer buttons {cancelButton, buttonResearch} default button buttonResearch cancel button cancelButton with icon 1
copy the result as list to {button_pressed, text_returned}

if (button_pressed is buttonResearch) and (text_returned is not "") then

    open location "http://www.wolframalpha.com/input/?i=" & my encode_text(text_returned, true, false)

    set a to "http://www.wolframalpha.com/input/?i="
    set b to my encode_text(text_returned, true, false)
    set c to a & b

    set myFile to (POSIX path of (path to temporary items)) & "curl_file.xml"
    do shell script "curl -L " & c & " -o " & myFile


end if

-- encoding high-ASCII characters:
on encode_char(this_char)
    set the ASCII_num to (the ASCII number this_char)
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    return ("%" & x & y) as string
end encode_char

-- TEXT ENCODING: encode spaces and high-level ASCII characters (those above 127)
-- encode_URL_A = encode most of the special characters reserved for use by URLs.
on encode_text(this_text, encode_URL_A, encode_URL_B)
    set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
    set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~'^\|*"
    set the URL_B_chars to ".-_:"
    set the acceptable_characters to the standard_characters
    if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
    if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
    set the encoded_text to ""
    repeat with this_char in this_text
        if this_char is in the acceptable_characters then
            set the encoded_text to (the encoded_text & this_char)
        else
            set the encoded_text to (the encoded_text & encode_char(this_char)) as string
        end if
    end repeat
    return the encoded_text
end encode_text

Come faccio ad accedere al file temporaneo?

    
posta Phoenix Ebner 01.06.2015 - 20:39
fonte

1 risposta

1

Questo fa parte della query. Le routine di codifica provengono dal link :

set defaultAnswer to "Albert Einstein"
set cancelButton to "Cancel"
set buttonResearch to "ReSearch"

display dialog "Query: " default answer defaultAnswer buttons {cancelButton, buttonResearch} default button buttonResearch cancel button cancelButton with icon 1
copy the result as list to {button_pressed, text_returned}

if (button_pressed is buttonResearch) and (text_returned is not "") then

    open location "http://www.wolframalpha.com/input/?i=" & my encode_text(text_returned, true, false)

end if

-- encoding high-ASCII characters:
on encode_char(this_char)
    set the ASCII_num to (the ASCII number this_char)
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    return ("%" & x & y) as string
end encode_char

-- TEXT ENCODING: encode spaces and high-level ASCII characters (those above 127)
-- encode_URL_A = encode most of the special characters reserved for use by URLs.
on encode_text(this_text, encode_URL_A, encode_URL_B)
    set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
    set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~'^\|*"
    set the URL_B_chars to ".-_:"
    set the acceptable_characters to the standard_characters
    if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
    if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
    set the encoded_text to ""
    repeat with this_char in this_text
        if this_char is in the acceptable_characters then
            set the encoded_text to (the encoded_text & this_char)
        else
            set the encoded_text to (the encoded_text & encode_char(this_char)) as string
        end if
    end repeat
    return the encoded_text
end encode_text

Il problema di pronunciare il risultato non è il parlare in sé, ma selezionare le parti rilevanti. Quindi meglio cercare uno strumento che faccia questo, o ancora meglio, utilizzare i servizi del sito web per questo, spesso hanno una sorta di interfaccia.

    
risposta data 02.06.2015 - 18:30
fonte

Leggi altre domande sui tag