-
Notifications
You must be signed in to change notification settings - Fork 4
/
Client.py
82 lines (63 loc) · 1.89 KB
/
Client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from pymumble_py3 import Mumble
from pymumble_py3 import constants
from pymumble_py3 import soundoutput
import pyaudio
import numpy as np
from array import array
import time
IP = "192.168.1.247"
NAME = "FT736R"
CERTFILE = "FT736R.pem"
KEYFILE = "FT736R-keys.pem"
AUDIO_DEVICE_INDEX = 2
ENABLE_TRANSMIT = False
#Setup connection to mumble server
mumble = Mumble(IP,NAME,certfile=CERTFILE,keyfile=KEYFILE,debug=False)
PyAudio = pyaudio.PyAudio()
#Setup stream to radio from mumble if transmit is enabled
stream_to_radio = PyAudio.open(48000,1,pyaudio.paInt16,False,True,None,AUDIO_DEVICE_INDEX,1920,ENABLE_TRANSMIT)
Sound = False
#Send audio from radio to mumble
def SendAudio(in_data,frame_count,time_info,status_flag):
mumble.sound_output.add_sound(in_data)
return (None,0)
stream_from_radio = None
#Send audio from mumble to radio
def ProcessSound(user,sound):
global Sound
stream_to_radio.write(sound.pcm)
Sound = True
#Callback for receiving audio from mumble
mumble.callbacks.set_callback(constants.PYMUMBLE_CLBK_SOUNDRECEIVED,ProcessSound)
#Set application name
mumble.set_application_string("HamRadioLink")
#Set codec profile
mumble.set_codec_profile("audio")
#Start mumble client
mumble.start()
#Wait to continue until we connect.
mumble.is_ready()
#Set bandwidth
mumble.set_bandwidth(96000)
#See if we actually connected.
print("Connected: "+str(mumble.connected==constants.PYMUMBLE_CONN_STATE_CONNECTED ))
#Enable callback if we are ready.
mumble.set_receive_sound(ENABLE_TRANSMIT)
stream_from_radio = PyAudio.open(48000,1,pyaudio.paInt16,True,False,AUDIO_DEVICE_INDEX,None,64,True,None,None,SendAudio)
last_state = False
#Used if transmitting.
while ENABLE_TRANSMIT:
if Sound:
if last_state != Sound:
#ser.write(10)
pass
last_state = True
Sound = False
else:
if last_state != Sound:
#ser.write(0)
pass
last_state = False
time.sleep(0.2)
while True:
time.sleep(1000)