forked from ggerganov/ggwave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-ggwave.py
41 lines (28 loc) · 952 Bytes
/
test-ggwave.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
import sys
import ggwave
# optionally disable logging
#ggwave.disableLog()
# create ggwave instance with default parameters
instance = ggwave.init()
payload = 'hello python'
# generate audio waveform for string "hello python"
waveform = ggwave.encode(payload, protocolId = 1, volume = 20, instance = instance)
# decode the audio waveform back to text
res = ggwave.decode(instance, waveform)
if res != payload.encode():
sys.exit(1)
# disable the Rx protocol - the decoding should fail
ggwave.rxToggleProtocol(protocolId = 1, state = 0)
instanceTmp = ggwave.init()
res = ggwave.decode(instanceTmp, waveform)
if res != None:
sys.exit(1)
ggwave.free(instanceTmp);
# re-enable the Rx protocol - the decoding should succeed
ggwave.rxToggleProtocol( protocolId = 1, state = 1)
instanceTmp = ggwave.init()
res = ggwave.decode(instance, waveform)
if res != payload.encode():
sys.exit(1)
ggwave.free(instanceTmp);
ggwave.free(instance);