Added some sample audio tracks to always be available

This commit is contained in:
Jono Targett 2023-06-13 20:09:10 +09:30
parent dd216e54d3
commit 87bd553bb8
14 changed files with 69 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
data/sampleaudio/SOURCE Normal file
View File

@ -0,0 +1 @@
https://www2.cs.uic.edu/~i101/SoundFiles/

Binary file not shown.

Binary file not shown.

BIN
data/sampleaudio/taunt.mp3 Normal file

Binary file not shown.

50
fileradio.py Normal file
View File

@ -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)

View File

@ -1,9 +1,12 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
import os
import sys
import requests import requests
import SoapySDR as soapy import SoapySDR as soapy
from radio import Radio from radio import Radio
from tuuube import Tuuube from tuuube import Tuuube
from fileradio import FileRadio
from flask import Flask, jsonify from flask import Flask, jsonify
from flasgger import Swagger from flasgger import Swagger
@ -257,6 +260,13 @@ if __name__ == '__main__':
stderr=subprocess.DEVNULL 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( app.run(
host='0.0.0.0', host='0.0.0.0',
threaded=True, threaded=True,

8
scripts/wav2mp3.sh Executable file
View File

@ -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