Angeliki/Grad Scripts

From XPUB & Lens-Based wiki

srttojs.py

Make subtitles 'linkable' for html

pip install pysrt
import pysrt, argparse

ap = argparse.ArgumentParser("srttojs")
ap.add_argument("srt")
args = ap.parse_args()

srt= pysrt.open(args.srt)
print("<div class='sub'>")
for t in srt:
    print ('<div><a data-start="{1}" href="#">{0}</a> {2}</div>'.format(t.start, t.start.ordinal/1000.0, t.text))
print ("</div>")

addmetadata.py

Add metadata to an audio file

pip install pydub
from pydub.utils import mediainfo
from pydub import AudioSegment
sound= AudioSegment.from_file("podcasts/podcast.20190501-1223-femalemale.mp3", format="mp3")
file=sound.export("podcasts/podcast.20190501-1223-femalemale-.mp3", tags={"title":"transformation for presence", "narrator":"angeliki", "topic":"female voice to male"})

metadatatohtml.py

Edit metadata for html preview

pip install pydub
from pydub import AudioSegment
from pydub.utils import mediainfo
import pprint

z = mediainfo("podcasts/3_podcast.mp3.mp3")

# sound= AudioSegment.from_file("podcasts/3_podcast.mp3", format="mp3")
# file=sound.export("out.mp3", tags={"podcaster":"lain"})
# print (mediainfo("out.mp3"))


def dict_to_html(dd, level=0):
    """
    Convert dict to html using basic html tags
    """
    import simplejson
    text = ''
    for k, v in dd.items():
        text += '<br>' + '&nbsp;'*(4*level) + '<b>%s</b>: %s' % (k, dict_to_html(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
    return text

def dict_to_html_ul(dd, level=0):
    """
    Convert dict to html using ul/li tags
    """
    import simplejson
    text = '<ul>'
    for k, v in dd.items():
        text += '<li><b>%s</b>: %s</li>' % (k, dict_to_html_ul(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
    text += '</ul>'
    return text

print (dict_to_html(z, level=0))


podcast

Make podcasts with one command that accesses microphone and soundcard

check: Command-line podcasts
#!/bin/bash
output=${1:-podcast}
arecord -Dpulse_monitor -f cd ${output}_sc.wav &
arecord -Dpulse -f cd ${output}_mic.wav 
ffmpeg -i ${output}_mic.wav -i ${output}_sc.wav -filter_complex amerge -ac 2 -c:a libmp3lame -q:a 4 ${ou$

today=$(date +%Y%m%d-%H%M);
mkdir -p "podcast.$today" 
mv podcast.$today podcasts/;
mv -v ${output}_sc.wav podcasts/podcast.$today/${output}_sc.$today.wav;
mv -v ${output}_mic.wav podcasts/podcast.$today/podcast_mic.$today.wav;
mv -v ${output}.mp3 podcasts/${output}.$today.mp3;

audiojs

femaletomale.sh

#!/bin/bash
today=$(date +%Y%m%d-%H%M);
output=${1:-distort}
arecord -Dpulse -f cd normal_$today.wav
rubberband -t 1.5 -p -5.5 normal_$today.wav ${output}_$today.wav

mkdir -p "normal" 
mv -v normal_$today.wav normal/normal_$today.wav;

maletofemale.sh

#!/bin/bash
today=$(date +%Y%m%d-%H%M)
output=${1:-distort}
arecord -Dpulse -f cd normal_$today.wav
rubberband -t 1.5 -p 3.0 normal_$today.wav ${output}_$today.wav

mkdir -p "storage" 
mv -v normal_$today.wav storage/
ffmpeg -i ${output}_$today.wav -vn -ar 44100 -ac 2 -ab 192k -f mp3 ${output}_$today.mp3
mv -v ${output}_$today.wav storage/