• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Speech Recognition (Stock price project)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Speech Recognition (Stock price project)


  • Subject: Speech Recognition (Stock price project)
  • From: Dennis Wurster <email@hidden>
  • Date: Mon, 13 Aug 2001 22:50:44 -0400

First off, thanks to the list about my 'speech impediment' question. You are all on the ball! I even got some responses that included some very clever scripts! What a great way to learn! :-D

So now that my 3-year-old is into knock-knock jokes, I've installed Speech Recognition ("Computer, Tell me a joke." ;-) and I'm interested in knowing more about how to format scripts so that they work will with SR. I've attempted to open the included 'Speakable Items' with Script Debugger, but it was a no go.

I want to be able to say "Computer, Apple Stock Price", have the script get the price, and then speak it back to me, while posting something like "AAPL 19.29 +.29" to the little text window with the caricature.

The thing is, I've already written the script, but I need to know more about how to 'mold' it to fit the interface of SR nicely? I hope I'm being clear...

Here's the script... it borrows heavily from one that I found on the web, and requires the RegEx OSAX. (I really need to get around to re-writing it without the OSAX...)

TIA,
-=Dennis=-

---------

--things to do... also pull out the change in price.

set dlgReply to (display dialog "Get a Yahoo! stock quote for this symbol:" default answer "" buttons {"Get Quote", "Cancel"} default button 1 giving up after 30)

if button returned of dlgReply is "Cancel" then
return
else
set daSymbol to allCaps(text returned of dlgReply)
end if

--for each ticker...

repeat with singleTicker in every word of daSymbol
-- make a temp file
set myFile to ((path to temporary items) as string) & "Stock Quote Script Temp"

-- fetch quote page
tell application "URL Access Scripting"
download "http://finance.yahoo.com/q"; to file myFile replacing yes form data "s=" & singleTicker & "&d=t"
quit
end tell

-- read HTML into a variable
open for access file myFile
set quoteHTML to (read file myFile to (get eof file myFile))
close access file myFile

-- get price from HTML in variable
--REMatch requires an OSAX. I wanted to write this without OSAXen, but this was *so* much easier
--this regular expression says "look for one or more numbers, then a decimal, then one or more numbers again, and have that whole thing wrapped in a 'bold' HTML tag"
--for the curious: words 1 through 3 of the matched string are "<", "b", and ">", respectively. The fourth word is the actual number.
set price to word 4 of (REMatch quoteHTML pattern "<b>[0-9]+\\.[0-9]+</b>")

--output
say "The latest stock price for ticker " & singleTicker & " is " & price

--throw out the temp file
tell application "Finder"
move file myFile to the trash
end tell
end repeat


on allCaps(daText)
-- very messy capitalization routine

-- initialize the variable
copy "" to newText
-- do the following for every letter of what's passed into this function
repeat with i from 1 to the count of character in daText

--put the current character into a variable
set curChar to character i of daText

--get the ASCII number of the current character, and put that into a variable
set curNum to ASCII number curChar

--if the ASCII number is between 97 and 122 inclusive...
if (curNum > 96) and (curNum < 123) then

--subtract 32 from this character's ASCII number, take the ASCII character of the result, and append it to whatever exists in newText
set newText to (newText & (ASCII character (curNum - 32))) as string
else

--this character is already upper case, so just append it to whatever exists in newText
set newText to (newText & curChar) as string
end if
end repeat

--send newText back as the result of the function
return newText
end allCaps

-------------------------------------------------------------------------
Dennis A. Wurster

Published in Element K's Adminsistration Journal
<http://www.elementkjournals.com/mad/>

Yo Hablo AppleScript. ;-)


  • Follow-Ups:
    • Re: Speech Recognition (Stock price project)
      • From: Paul Skinner <email@hidden>
  • Prev by Date: Re: does property exists in a record
  • Next by Date: Bringing an app to the front
  • Previous by thread: Fwd: [PR] 24U Appearance OSAX 1.2
  • Next by thread: Re: Speech Recognition (Stock price project)
  • Index(es):
    • Date
    • Thread