diff --git a/data/sampleaudio/BabyElephantWalk60.mp3 b/data/sampleaudio/BabyElephantWalk60.mp3 new file mode 100644 index 0000000..ba83ed3 Binary files /dev/null and b/data/sampleaudio/BabyElephantWalk60.mp3 differ diff --git a/data/sampleaudio/CantinaBand3.mp3 b/data/sampleaudio/CantinaBand3.mp3 new file mode 100644 index 0000000..8fd4f5f Binary files /dev/null and b/data/sampleaudio/CantinaBand3.mp3 differ diff --git a/data/sampleaudio/CantinaBand60.mp3 b/data/sampleaudio/CantinaBand60.mp3 new file mode 100644 index 0000000..935ddea Binary files /dev/null and b/data/sampleaudio/CantinaBand60.mp3 differ diff --git a/data/sampleaudio/Fanfare60.mp3 b/data/sampleaudio/Fanfare60.mp3 new file mode 100644 index 0000000..13541b4 Binary files /dev/null and b/data/sampleaudio/Fanfare60.mp3 differ diff --git a/data/sampleaudio/ImperialMarch60.mp3 b/data/sampleaudio/ImperialMarch60.mp3 new file mode 100644 index 0000000..05d6c6e Binary files /dev/null and b/data/sampleaudio/ImperialMarch60.mp3 differ diff --git a/data/sampleaudio/PinkPanther30.mp3 b/data/sampleaudio/PinkPanther30.mp3 new file mode 100644 index 0000000..3a0b714 Binary files /dev/null and b/data/sampleaudio/PinkPanther30.mp3 differ diff --git a/data/sampleaudio/PinkPanther60.mp3 b/data/sampleaudio/PinkPanther60.mp3 new file mode 100644 index 0000000..894a7e3 Binary files /dev/null and b/data/sampleaudio/PinkPanther60.mp3 differ diff --git a/data/sampleaudio/SOURCE b/data/sampleaudio/SOURCE new file mode 100644 index 0000000..648d57e --- /dev/null +++ b/data/sampleaudio/SOURCE @@ -0,0 +1 @@ +https://www2.cs.uic.edu/~i101/SoundFiles/ \ No newline at end of file diff --git a/data/sampleaudio/StarWars3.mp3 b/data/sampleaudio/StarWars3.mp3 new file mode 100644 index 0000000..da6f7d8 Binary files /dev/null and b/data/sampleaudio/StarWars3.mp3 differ diff --git a/data/sampleaudio/StarWars60.mp3 b/data/sampleaudio/StarWars60.mp3 new file mode 100644 index 0000000..6284b4e Binary files /dev/null and b/data/sampleaudio/StarWars60.mp3 differ diff --git a/data/sampleaudio/taunt.mp3 b/data/sampleaudio/taunt.mp3 new file mode 100644 index 0000000..43e5d3e Binary files /dev/null and b/data/sampleaudio/taunt.mp3 differ diff --git a/fileradio.py b/fileradio.py new file mode 100644 index 0000000..d225214 --- /dev/null +++ b/fileradio.py @@ -0,0 +1,50 @@ +from streamer import Streamer, is_alive +import subprocess +import time +import sys +import os + +class FileRadio(Streamer): + PORT = 8554 + + def __init__(self, path): + self.path = path + self.basename = os.path.basename(self.path) + self.name, self.ext = os.path.splitext(self.basename) + + super().__init__() + + def _stream_path(self): + return f":{FileRadio.PORT}/sample/{self.name}" + + def _stream_thread(self): + self.playback = subprocess.Popen( + [ + '/usr/bin/ffmpeg', '-re', '-stream_loop', '-1', '-i', + f"{self.path}", '-c', 'copy', + '-f', 'rtsp', f"rtsp://localhost{self._stream_path()}" + ], + stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) + + while self.run: + if not is_alive(self.playback): + print('Playback failed, aborting stream.', file=sys.stderr) + break + time.sleep(0.1) + + self.run = False + + self.playback.kill() + self.playback.wait() + self.playback = None + + +if __name__ == '__main__': + fr = FileRadio('./data/sampleaudio/taunt.mp3') + fr.start_stream() + + while True: + time.sleep(1) diff --git a/microservice.py b/microservice.py index 776bd47..6c0dac2 100755 --- a/microservice.py +++ b/microservice.py @@ -1,9 +1,12 @@ #! /usr/bin/env python3 +import os +import sys import requests import SoapySDR as soapy from radio import Radio from tuuube import Tuuube +from fileradio import FileRadio from flask import Flask, jsonify from flasgger import Swagger @@ -257,6 +260,13 @@ if __name__ == '__main__': stderr=subprocess.DEVNULL ) + for path, _, files in os.walk('./data/sampleaudio'): + for file in files: + name,ext = os.path.splitext(file) + if ext == '.mp3': + tubes[name] = FileRadio(f"{path}/{file}") + tubes[name].start_stream() + app.run( host='0.0.0.0', threaded=True, diff --git a/scripts/wav2mp3.sh b/scripts/wav2mp3.sh new file mode 100755 index 0000000..ccbbbb7 --- /dev/null +++ b/scripts/wav2mp3.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +for arg in "$@"; do + path="${arg%/*}" + file="${arg##*/}" + filename="${file%%.*}" + ffmpeg -i $path/$file -vn -ar 44100 -ac 2 -b:a 100k $path/$filename.mp3 +done