Angeliki/Grad Scripts: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 84: Line 84:
mv -v ${output}.mp3 podcasts/${output}.$today.mp3;
mv -v ${output}.mp3 podcasts/${output}.$today.mp3;
</syntaxhighlight >
</syntaxhighlight >
=== audiojs ===

Revision as of 12:50, 14 May 2019

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