Advertisement
omegastripes

phonetic_notation_via_upodn_com.vbs

May 11th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim strText, strLiteral, strPhonetic
  2.  
  3. strText = "Transcription in the linguistic sense is the systematic representation of language in written form."
  4. GetFoneticNotation strText, 0, "on", strLiteral, strPhonetic
  5. MsgBox strLiteral & vbcrlf & vbcrlf & strPhonetic
  6.  
  7. Sub GetFoneticNotation(strText, strOptIpa, strOptStrs, strLiteral, strPhonetic)
  8.     ' http://upodn.com/phon.php
  9.    ' usage
  10.    ' strText - text to get fonetic notation
  11.    ' strOptIpa:
  12.    ' 0 - IPA
  13.    ' 1 - American Phonetic Alphabet
  14.    ' 2 - SAMPA
  15.    ' 3 - Shavian
  16.    ' strOptStrs:
  17.    ' on | off - Mark word stress
  18.    ' strLiteral - return recognized text
  19.    ' strPhonetic - return phonetic notation
  20.    Dim strData, strResp
  21.     strData = "intext=" & escape(strText) & "&ipa=" & strOptIpa & "&stress=" & strOptStrs
  22.     With CreateObject("Msxml2.XMLHTTP")
  23.         .Open "POST", "http://upodn.com/phon.php", False
  24.         .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  25.         .SetRequestHeader "Content-Length", Len(strData)
  26.         .Send strData
  27.         strResp = .ResponseText
  28.     End With
  29.     With New RegExp
  30.         .Pattern = "<table[\s\S]*<tr[\s\S]*<td[\s\S]*>([\s\S]*)</td>[\s\S]*<td[\s\S]*<font[\s\S]*>([\s\S]*)</font>[\s\S]*</td>[\s\S]*</tr>[\s\S]*</table>"
  31.         .Global = True
  32.         .IgnoreCase = True
  33.         With .Execute(strResp)
  34.             If .Count = 1 Then
  35.                 strLiteral = .Item(0).SubMatches(0)
  36.                 With CreateObject("htmlfile")
  37.                     .write strLiteral
  38.                     strLiteral = UnEscape(.getElementsByTagName("body")(0).innerText)
  39.                 End With
  40.                 strPhonetic = .Item(0).SubMatches(1)
  41.                 With CreateObject("htmlfile")
  42.                     .write strPhonetic
  43.                     strPhonetic = .getElementsByTagName("body")(0).innerText
  44.                 End With
  45.             End If
  46.         End With
  47.     End With
  48. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement