A library allowing for streaming and playback of audio files from server to client over a socket connection.
Project description
PyAudioStream
A library allowing for streaming and playback of audio files from server to client over a socket connection.
Usage
Working demo is provided in the Examples folder. For a quick check of installation you can perform:
from PyAudioStream import audiostream
test = audiostream.AudioStreamServer()
test.create_server('127.0.0.1', 8889)
Server
Create a server and start accepting new connections
class ExampleServer(AudioStreamServer):
...
...
server = ExampleServer()
server.create_server(host=host, port=port)
server.accept_new_connections()
Retrieve messages from connected clients
for client, addr in server.get_connected_clients():
message = server.retrieve_message_from_client(client)
Unpack the message and respond accordingly
for request in message:
request_type, request_command, audio_file_context = server.unpack_request(request)
if request_type == MessageType.STREAM:
server.handle_audio_frames_request(client, addr, audio_file_context)
if request_command == MessageCommand.AUDIOFILESLIST:
self.send_audio_files_list_to_client(client, self._get_audio_files_list())
if request_command == MessageCommand.AUDIO_PROPERTIES:
self.send_audio_file_properties(client, self._get_audio_properties(audio_file_context))
Example usage provides a basic implementation of reading the audio file and its frames, you will have to use the code from sample or create your own solution to this.
def read_audio_file(self, audio_file_path):
audio_file = soundfile.SoundFile(audio_file_path)
return audio_file
def _prepare_frames_list(self, frames_array):
ready_frames = []
logging.info(f"Frames to send {frames_array}")
for frame in frames_array:
for frame_for_channel in frame:
ready_frames.append(int(frame_for_channel))
return ready_frames
Client
Create a client instance and connect to server
class ExampleClient(AudioStreamClient):
...
...
client = ExampleClient()
client.connect(host, port)
Ask the server for available audio files
song_list = client.retrieve_audio_files_list()
Retrieve the desired audio files properties
chosen_song_title = client.retrieve_audio_file_properties(chosen_song_title)
Request the server to start streaming audio frames
client.start_audio_stream(chosen_song_title)
Retrieve the audio frames and play them in a loop until the audio playback is finished
played_frame = 0
data = []
received_all_data = False
while True:
if not received_all_data:
audio_data = self.retrieve_audio_stream()
if not audio_data:
pass
else:
if MessageType.ENDOFAUDIOFILE in audio_data:
received_all_data = True
else:
data.append(audio_data)
if received_all_data:
if len(data) - 1 <= played_frame:
break
if len(data) - 1 >= played_frame:
if MessageType.ENDOFAUDIOFILE in data[played_frame]:
break
self.play_streamed_data(data[played_frame])
played_frame += 1
client comes with basic audio playback functionality using PyAudio in the form of initialize_audio_playback and play_streamed_data methods.
Regenerating documentation:
inside docs subdirectory
make html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyAudioStream-TouwaStar-0.0.2.tar.gz.
File metadata
- Download URL: PyAudioStream-TouwaStar-0.0.2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
556241b7c53002406f3024a32658f0d0fd91d188fbfd79313d9ab571e0fccdd3
|
|
| MD5 |
5193e3bdec56da8c020a596cfa2862f5
|
|
| BLAKE2b-256 |
92b7e0618ccf0d40293d2dc78757f40f97f0c960dd6a7f30c16d605554810d2e
|
File details
Details for the file PyAudioStream_TouwaStar-0.0.2-py3-none-any.whl.
File metadata
- Download URL: PyAudioStream_TouwaStar-0.0.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2556ad1619e22c9e1dd612295466710c5cf7734afd56dc465f537f9312e6e94d
|
|
| MD5 |
2b5b026aaa48a495e8fe2cd010b390a1
|
|
| BLAKE2b-256 |
5d06ec79e33eb1e2274b1ff741c9cac88ae56ab0ed838114d2c2ed5130b492ac
|