Script Library: 1247 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Archive version of: intercom.r ... version: 6 ... notchent 11-Nov-2009

REBOL [
    Title: "Intercom (Voice Communicator)"
    date: 7-nov-2009
    file: %intercom.r
    author:  Nick Antonaccio
    purpose: {
        A walkie-talkie push-to-talk type of VOIP application.  Extremely simple -
        just records sound from mic to .wav file, then transfers the wave file to
        another IP (where the same program is running), for playback.  Sender
        and receiver open in separate processes, and both run in forever loops
        to enable continuous communication back and forth.
        Taken from the tutorial at http://musiclessonz.com/rebol.html
    }
]

write %wt-receiver.r {
    REBOL []
    ; print join "Listening at " read join dns:// read dns://  ; (show IP)
    if error? try [c: first t: wait open/binary/no-wait tcp://:8] [quit]
    wait 0  s: open sound://
    forever [
        d: copy wait c
        if error? try [i: load to-string copy/part d start: find d #""] [
            print "^lclient closed" close t close c close s wait 1 quit
        ]
        remove/part d next start
        while [i/1 > length? d] [append d copy c]
        insert s load to-binary decompress d
    ]
}
launch %wt-receiver.r
lib: load/library %winmm.dll
mciExecute: make routine! [c [string!] return: [logic!]] lib "mciExecute"
if (ip: ask "Connect to IP (none = localhost):  ") = "" [ip: "localhost"]
if error? try [s: open/binary/no-wait rejoin [tcp:// ip ":8"]] [quit]
mciExecute "open new type waveaudio alias buffer1"
forever [
    if (ask "^lPress [ENTER] to send sound ('q' to quit):  ") = "q" [quit]
    mciExecute "record buffer1"
    ask "^l*** YOU ARE NOW RECORDING SOUND ***   Press [ENTER] to send:  "
    mciExecute "save buffer1 r.wav"
    mciExecute "delete buffer1 from 0"
    d: compress to-string read/binary %r.wav
    insert d append remold [length? d] #""
    insert s d
]