Phonetic transformations demo
For DT2112 ASR lecture; unused
from IPython.core.display import display, HTML
import json
# Define the phonetic transformation steps
modifications = [
[("find him", "/faɪnd hɪm/"),
("around this", "/əɹaʊnd ðɪs/"),
("let me", "/lɛt mi:/")],
[("fin<span class='hl_red'>d h</span>im", "/faɪnd hɪm/"),
("aroun<span class='hl_red'>d th</span>is", "/əɹaʊnd ðɪs/"),
("le<span class='hl_red'>t</span> me", "/lɛt mi:/")],
[("fin<span class='hl_red'>d h</span>im", "/faɪn<span class='hl_red'>d h</span>ɪm/"),
("aroun<span class='hl_red'>d th</span>is", "/əɹaʊn<span class='hl_red'>d ð</span>ɪs/"),
("le<span class='hl_red'>t</span> me", "/lɛ<span class='hl_red'>t</span> mi:/")],
[("fin<span class='hl_red'>d h</span>im", "/faɪn ɪm/"),
("aroun<span class='hl_red'>d th</span>is", "/əɹaʊn ɪs/"),
("le<span class='hl_red'>t</span> me", "/lɛ mi:/")],
[("fin<span class='hl_red'>d h</span>im", "/faɪnɪm/"),
("aroun<span class='hl_red'>d th</span>is", "/əɹaʊnɪs/"),
("le<span class='hl_red'>t</span> me", "/lɛmi:/")],
[("fin<span class='hl_red'>d h</span>im", "/faɪɾ̃ɪm/"),
("aroun<span class='hl_red'>d th</span>is", "/əɹaʊɾ̃ɪs/"),
("le<span class='hl_red'>t</span> me", "/lɛmi:/")]
]
# Function to render animation in Jupyter Notebook
def render_animation():
steps_json = json.dumps(modifications)
html_template = f"""
<style>
@keyframes fadeIn {{
from {{ opacity: 0; }}
to {{ opacity: 1; }}
}}
.phoneme-step {{
font-size: 20px;
font-family: Arial, sans-serif;
margin-bottom: 10px;
animation: fadeIn 1s;
}}
.hl_red {{
color: red;
font-weight: bold;
}}
</style>
<h1>Deletion</h1>
<span> </span>
<div id='phoneme-display'></div>
<script>
let steps = {steps_json};
let index = 0;
function updateDisplay() {{
let displayDiv = document.getElementById('phoneme-display');
displayDiv.innerHTML = steps[index].map(pair => `<div class='phoneme-step'><strong>${{pair[0]}}</strong>: ${{pair[1]}}</div>`).join('');
if (index < 5) {{
index = (index + 1) % steps.length;
setTimeout(updateDisplay, 2000);
}}
}}
updateDisplay();
</script>
"""
display(HTML(html_template))
# Call the function to display the animation in Jupyter Notebook
render_animation()