-
Notifications
You must be signed in to change notification settings - Fork 14
/
sound.py
63 lines (39 loc) · 1.17 KB
/
sound.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
#!/usr/bin/python3
# Call scripty with:
# ./sound.py CAM_IP FILENAME
import sys
import os
from xmcam import *
from xmconst import *
from time import sleep
CAM_IP = sys.argv[1]
FILE = sys.argv[2]
CAM_PORT = 34567
if __name__ == '__main__':
cam = XMCam(CAM_IP, CAM_PORT, 'admin', '')
login = cam.cmd_login()
print(login)
sleep(0.1)
streamconn = cam.create_sub_connection(True)
sleep(0.1)
success, pcm_audio_path = XMCam.talk_convert_to_pcm(FILE)
if success: # if audio converted into PCM successfully
streamconn.cmd_talk_claim()
print("CLAIM")
sleep(0.1)
cam.cmd_talk_start()
print("START")
audio_chunks = XMCam.talk_get_chunks(pcm_audio_path)
if audio_chunks is not None:
for audio_chunk in audio_chunks:
streamconn.cmd_talk_send_stream(audio_chunk)
# Sufficient wait for playing whole file
stat = os.stat(pcm_audio_path).st_size
sleep(stat / 8000)
sleep(0.05)
cam.cmd_talk_stop()
print("END")
sleep(0.1)
sleep(0.1)
cam.disconnect()
print("END")