Hallo Leute,
ich bin heute morgen zufällig über Mikrofon gestolpert.
Dort geht es über Sprach-Streaming, auch bekannt als VoIP.
Das fand ich interessant und hab mich deswegen ein bisschen damit beschäftigt.
Das Beispiel von Eukalyptus und ein anderes Beispiel und mein Wissen hab ich dann zusammengeschmissen:
Jetzt hab ich zwei Skripte:
stream.au3
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Description=Stream senden
#AutoIt3Wrapper_Res_Fileversion=0.1.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (C) 2010 by Jan Kirsten
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <BassEnc.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
;Bass Variablen
Global $device, $input, $EncHandle, $RecHandle, $Bitrate = 128, $KHZ = 44100, $levels, $levelL = 0, $levelR = 0, $temp, $EncState = False
;TCP Variablen
Global $ConnectedSocket, $szData
Global $szIPADDRESS = InputBox("IP", "IP-Adresse eingeben:")
Global $nPORT = 3344
_BASS_STARTUP()
_BASS_Encode_STARTUP()
$basscb_dll = DllOpen("BASSCB.dll")
;Gui
#Region ### START Koda GUI section ###
$hGui = GUICreate("Jan-Sprachchat", 322, 281, 347, 158)
GUICtrlCreateLabel("Audiogerät ausählen:", 10, 20, 172, 12)
$hDevice = GUICtrlCreateCombo("", 10, 38, 300, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL))
GUICtrlCreateLabel("Eingabetyp auswählen:", 11, 69, 172, 12)
$hInput = GUICtrlCreateCombo("", 10, 88, 300, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL))
$hPeakL = GUICtrlCreateProgress(10, 136, 300, 10)
$hPeakR = GUICtrlCreateProgress(10, 151, 300, 10)
GUICtrlCreateLabel("An Encoder gesendete Daten:", 11, 175, 172, 12)
$hEncCount = GUICtrlCreateLabel("", 11, 198, 200, 12)
$hStart = GUICtrlCreateButton("Start", 20, 226, 130, 28, $WS_GROUP)
$hStop = GUICtrlCreateButton("Stop", 170, 226, 130, 28, $WS_GROUP)
GUICtrlCreateLabel("Copyright (C) 2010 by Jan Kirsten", 11, 260, 172, 12)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;Tcp initialisieren
TCPStartup()
;Verbindungsversuch
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
;Bei Fehler
If @error Then
MsgBox(4112, "Fehler", "TCP-Connect schlug mit folgendem WSA-Fehler fehl: " & @error)
Exit
EndIf
;Bass Einstellungen
_BASS_SetConfig($BASS_CONFIG_REC_BUFFER, 1000)
;Initialisieren
$device = _GetDevices()
_BASS_RecordInit($device)
$input = _GetInputs()
$RecHandle = _BASS_RecordStart($KHZ, 2, _makelong($BASS_SAMPLE_FX, 500), "_RecCallBack")
$temp = DllCall($basscb_dll, "dword", "RecordStart", "dword", $KHZ, "dword", 2, "dword", _makelong($BASS_SAMPLE_FX, 10))
$timer = TimerInit()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hDevice
_SelectDevice()
Case $hInput
_SelectInput()
Case $hStart
_Start()
Case $hStop
_Stop()
GUICtrlSetState($hGui, $GUI_DISABLE)
EndSwitch
Sleep(5)
$peak = _BASS_ChannelGetLevel($RecHandle)
If Not @error Then
$temp = (_LoWord($peak) / 32768) * 100
If $temp > $levelL Then $levelL = $temp
$temp = (_HiWord($peak) / 32768) * 100
If $temp > $levelR Then $levelR = $temp
GUICtrlSetData($hPeakL, $levelL)
GUICtrlSetData($hPeakR, $levelR)
$levelL -= 1
$levelR -= 1
EndIf
If TimerDiff($timer) > 200 Then
$timer = TimerInit()
If $EncState Then
GUICtrlSetData($hEncCount, _BASS_Encode_GetCount( $EncHandle, $BASS_ENCODE_COUNT_IN))
EndIf
EndIf
WEnd
Func _Start()
GUICtrlSetState($hDevice, $GUI_DISABLE)
GUICtrlSetState($hInput, $GUI_DISABLE)
GUICtrlSetState($hStart, $GUI_DISABLE)
GUICtrlSetState($hStop, $GUI_ENABLE)
$EncHandle = _BASS_Encode_Start( $RecHandle, 'lame -r -x -b 128 -h - -', 0, "_Callback_Enc")
$EncState = True
EndFunc ;==>_Start
Func _Stop()
GUICtrlSetState($hDevice, $GUI_ENABLE)
GUICtrlSetState($hInput, $GUI_ENABLE)
GUICtrlSetState($hStart, $GUI_ENABLE)
GUICtrlSetState($hStop, $GUI_DISABLE)
_BASS_Encode_Stop( $EncHandle)
$EncState = False
EndFunc ;==>_Stop
Func _RecCallBack($handle, $buffer, $length, $user)
Return 1
EndFunc ;==>_RecCallBack
Func _SelectDevice()
Local $new = _GUICtrlComboBox_GetCurSel($hDevice)
If $new = $device Then Return
_BASS_RecordFree()
_BASS_RecordSetDevice($new)
_BASS_Recordinit($new)
GUICtrlSetData($hInput, "", "")
_GetInputs()
$RecHandle = _BASS_RecordStart($KHZ, 2, _makelong($BASS_SAMPLE_FX, 500), "_RecCallBack")
$device = $new
EndFunc ;==>_SelectDevice
Func _SelectInput()
Local $new = _GUICtrlComboBox_GetCurSel($hInput)
If $new = $input Then Return
_BASS_RecordSetInput($new, $BASS_INPUT_ON, -1)
$input = $new
EndFunc ;==>_SelectInput
Func _GetDevices()
Local $count = 0, $info, $name = "", $sdef = "", $idef = 0
While 1
$info = _BASS_RecordGetDeviceInfo($count)
If @error Then ExitLoop
$count += 1
If BitAND($info[2], $BASS_DEVICE_ENABLED) Then $name &= $info[0] & "|"
If BitAND($info[2], $BASS_DEVICE_DEFAULT) Then
$sdef = $info[0]
$idef = $count
EndIf
WEnd
GUICtrlSetData($hDevice, $name, $sdef)
Return $idef - 1
EndFunc ;==>_GetDevices
Func _GetInputs()
Local $count = 0, $info, $name = "", $flags, $sdef = "", $idef = 0
$info = _BASS_RecordGetInputName($count)
While $info <> ""
$flags = _BASS_RecordGetInput($count)
$count += 1
$name &= $info & "|"
If BitAND($flags[0], $BASS_INPUT_OFF) = 0 Then
$sdef = $info
$idef = $count
EndIf
$info = _BASS_RecordGetInputName($count)
WEnd
GUICtrlSetData($hInput, $name, $sdef)
Return $idef - 1
EndFunc ;==>_GetInputs
Func _exit()
;Bass beenden
If _BASS_Encode_IsActive( $EncHandle) Then _BASS_Encode_Stop( $EncHandle)
_BASS_RecordFree()
;Tcp beenden
TCPShutdown()
Exit
EndFunc ;==>_Exit
Func _Callback_Enc($handle, $channel, $buffer, $length, $user)
If Not $length Then
$length = 4012
Else
$length = Dec(StringReplace($length, "0x", ""))
EndIf
Local $tempbuffer = DllStructCreate("byte[" & $length & "]", $buffer) ;???
TCPSend($ConnectedSocket, DllStructGetData($tempbuffer, 1) & @CRLF)
EndFunc ;==>Bass_Callback_Enc
und
hear.au3
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Description=Stream empfangen
#AutoIt3Wrapper_Res_Fileversion=0.1.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (C) 2010 by Jan Kirsten
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Includes
#include <BassEnc.au3>
#include <GUIConstantsEx.au3>
;Dlls laden
_BASS_STARTUP()
_BASS_Encode_STARTUP()
$basscb_dll = DllOpen("BASSCB.dll")
;Variablen
Global $szIPADDRESS = @IPAddress1
Global $nPORT = 3344
Global $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Global $msg, $recv
;Bass initialisieren
_BASS_Init(0, -1, 44100, 0, "")
Global $stream = _BASS_StreamCreate(44100, 2, 0, $STREAMPROC_PUSH, "")
;Tcp starten
TCPStartup()
;Socket erstellen
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
;Bei Fehler
If $MainSocket = -1 Then Exit
;Gui
$GOOEY = GUICreate("Server (IP: " & $szIPADDRESS & ")", 300, 200)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()
;Auf Verbindung warten
$ConnectedSocket = -1
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
;Ip herausfinden
$szIP_Accepted = SocketToIP($ConnectedSocket)
;Stream abspielen
_Bass_ChannelPlay($stream, 1)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
;Empfangen
$recv = TCPRecv($ConnectedSocket, 4012)
If $recv <> "" Then
;Abspielen
$tempbuffer = DllStructCreate("byte[4096]")
DllStructSetData($tempbuffer, 1, $recv)
_BASS_StreamPutData($stream, DllStructGetPtr($tempbuffer), 4096)
;Daten in Input schreiben
GUICtrlSetData($edit, _
$recv & @CRLF & GUICtrlRead($edit))
EndIf
WEnd
If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
[/autoit] [autoit][/autoit] [autoit]Func SocketToIP($SHOCKET)
Global $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
[/autoit] [autoit][/autoit] [autoit]$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
[/autoit] [autoit][/autoit] [autoit]Return $aRet
EndFunc ;==>SocketToIP
Das Problem ist, dass man nur in Abständen ein Rauschen hört.
Es kann sein, dass die Übertragung zu langsam ist oder oder oder....
Kann mir da jemand helfen?
Im Anhang findet ihr alle Dateien. (Konnte nur 7z, zip war zu groß)
autoit.de/wcf/attachment/8804/