AmmosSource
guix
Last change
on this file since ec7df22 was ec7df22, checked in by recknagel <recknagel@…>, 3 years ago |
final bugfix to imports
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[1e781ba] | 1 | import sys
|
---|
| 2 | import os
|
---|
[ec7df22] | 3 |
|
---|
| 4 | sys.path.append('../src/')
|
---|
[1e781ba] | 5 |
|
---|
| 6 | import socket
|
---|
| 7 |
|
---|
| 8 | import numpy as np
|
---|
| 9 | import scipy.io.wavfile as wavfile
|
---|
| 10 |
|
---|
[ec7df22] | 11 | from ammosreader.AmmosAudioSocketReader import AmmosAudioSocketReader
|
---|
[1e781ba] | 12 |
|
---|
| 13 |
|
---|
| 14 | if __name__ == '__main__':
|
---|
| 15 | frames = []
|
---|
| 16 |
|
---|
| 17 | # create socket
|
---|
| 18 | in_socket = socket.socket()
|
---|
| 19 | in_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
---|
| 20 | in_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
---|
| 21 | in_socket.bind(('127.0.0.1', 12345))
|
---|
| 22 | print('Waiting for connection')
|
---|
| 23 | in_socket.listen(1)
|
---|
| 24 | conn, _ = in_socket.accept()
|
---|
| 25 | print('Connected')
|
---|
| 26 |
|
---|
| 27 | # create AmmosAudioSocketReader
|
---|
| 28 | socket_reader = AmmosAudioSocketReader(conn)
|
---|
| 29 |
|
---|
| 30 | print('Reading Frames')
|
---|
| 31 | while True:
|
---|
| 32 | try:
|
---|
| 33 | frames.append(socket_reader.read_next_frame())
|
---|
| 34 | except KeyboardInterrupt:
|
---|
| 35 | break
|
---|
| 36 |
|
---|
| 37 | # write frames to wav file
|
---|
| 38 | print('Writing frames to Wav File')
|
---|
| 39 | audio = np.concatenate([frame[0] for frame in frames])
|
---|
| 40 | print(audio)
|
---|
| 41 | wavfile.write(f"test.wav", frames[0][1], audio) |
---|
Note:
See
TracBrowser
for help on using the repository browser.