Skip to content

Instantly share code, notes, and snippets.

@7shi
Created May 15, 2020 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/3befffaf8ee5afcbc4a5d89074e771a7 to your computer and use it in GitHub Desktop.
Save 7shi/3befffaf8ee5afcbc4a5d89074e771a7 to your computer and use it in GitHub Desktop.
[py][F#] Esperanta Alfabeto
import wintts
voice = wintts.getvoice("Filip")
phonemes = "A B TS CH D E F G JH H X I J ZH K L M N O P R S SH T U W V Z".split()
vowels = "A E I O U".split()
def getname(phoneme):
v = "" if phoneme in vowels else " O"
return phoneme + v + " lng"
abc = ["E S . P E . R S1 A N . T A", "A L . F A . B S1 E lng . T O"]
wintts.save(voice, wintts.pron(*abc), "01.wav")
for i, ph in enumerate(phonemes):
wintts.save(voice, wintts.pron(getname(ph)), "%02d.wav" % (i + 3))
TARGET = alfabeto
MKWAV = ~/bin/wintts -o $$wav `python ssml_lfn.py -l pl-PL -f $$txt`
SILENT = ffmpeg -t 00:00:02 -f s16le -i /dev/zero -acodec pcm_s16le -ar 22050 -ac 1 $$wav
MKAVI = ffmpeg -loop 1 -i $$png -i $$wav -vcodec mpeg4 -acodec pcm_s16le -shortest $$avi
all: $(TARGET).mp4
clean:
rm -f $(TARGET).mp4 $(TARGET).lst *.avi *.png *.wav
$(TARGET).mp4: $(TARGET).lst
ffmpeg -f concat -i $< -vcodec libx264 -acodec aac -pix_fmt yuv420p $@
$(TARGET).lst: avi
for avi in *.avi; do echo file $$avi; done > $@
define chgext
`echo $1 | sed 's/\.[^.]*$$/.$2/'`
endef
define exists
if [ ! -f $1 ]; then echo $1; $2; fi
endef
define forpng
for png in *.png; do avi=$(call chgext,$$png,avi); wav=$(call chgext,$$png,wav); txt=$(call chgext,$$png,txt); $1; done
endef
avi: png wav
$(call forpng,$(call exists,$$avi,$(MKAVI)))
wav:
py.exe alfabeto.py
rm -f 00.wav
wav=00.wav; $(SILENT)
cp 00.wav 02.wav
cp 00.wav 31.wav
png:
fsharpc mkpngtxt.fsx
./mkpngtxt.exe
#r "System"
#r "System.Drawing"
#r "System.Windows.Forms"
open System
open System.Drawing
open System.IO
open System.Windows.Forms
let font = new Font("Arial", 26.f, FontStyle.Regular)
let bgcols = [| Color.White; Color.FromArgb(0xb0, 0xd0, 0xff) |]
let w, margin = 640, 6
let h = w / 4 * 3
let bmp = new Bitmap(w, h)
let g = Graphics.FromImage bmp
let lines =
[|"Esperanta alfabeto"; "";
"A B C Ĉ D"; "E F G Ĝ H Ĥ"; "I J Ĵ K L M N"; "O P R S Ŝ T"; "U Ŭ V Z";
""; "sk-SK"|]
let locale = lines.Length - 1
let flags = TextFormatFlags.NoPadding ||| TextFormatFlags.WordBreak
let proposedSize = Size(w, Int32.MaxValue)
let measure g line =
TextRenderer.MeasureText(g, line, font, proposedSize, flags)
let sizes = lines |> Array.map (measure g)
let maxw = sizes |> Seq.skip 1 |> Seq.map (fun size -> size.Width) |> Seq.max
let allh = sizes |> Seq.map (fun size -> size.Height + margin * 2) |> Seq.sum
let x = (w - maxw) / 2
let draw sel =
g.Clear(Color.White)
let mutable p = Point(x, (h - 32 - allh) / 2)
let n = ref 0
lines |> Seq.iteri (fun i line ->
let size = measure g line
if i < 2 || i > 6 then
p.X <- (w - size.Width) / 2
let bg = bgcols.[if i = 0 && sel = 1 then 1 else 0]
TextRenderer.DrawText(g, line, font, p, Color.Black, bg, flags)
else
p.X <- x
for ch in line do
let bg = bgcols.[if !n = sel - 3 then 1 else 0]
let s = ch.ToString()
let sz = measure g s
if ch <> ' ' then
TextRenderer.DrawText(g, s, font, p, Color.Black, bg, flags)
n := !n + 1
p.X <- p.X + sz.Width
p.Y <- p.Y + size.Height + margin * 2)
for i = 0 to 31 do
draw i
bmp.Save(sprintf "%02d.png" i, Imaging.ImageFormat.Png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment