|
1 | 1 | <script lang="ts"> |
2 | 2 | import { Volume2 } from 'lucide-svelte'; |
3 | 3 |
|
4 | | - function playSound() { |
5 | | - const audio = new Audio('/sounds/codevogel.mp3'); |
6 | | - audio.play(); |
| 4 | + let genderSoundNL: 'm' | 'f' = $state('f'); |
| 5 | + let genderSoundUK: 'm' | 'f' = $state('m'); |
| 6 | +
|
| 7 | + const audioNLMale = '/sounds/codevogel-nl-m.mp3'; |
| 8 | + const audioNLFemale = '/sounds/codevogel-nl-f.mp3'; |
| 9 | + const audioENMale = '/sounds/codevogel-en-m.mp3'; |
| 10 | + const audioENFemale = '/sounds/codevogel-en-f.mp3'; |
| 11 | +
|
| 12 | + function playSound(locale: 'nl' | 'en') { |
| 13 | + switch (locale) { |
| 14 | + case 'nl': |
| 15 | + new Audio(genderSoundNL === 'm' ? audioNLMale : audioNLFemale).play(); |
| 16 | + genderSoundNL = genderSoundNL === 'm' ? 'f' : 'm'; |
| 17 | + break; |
| 18 | + case 'en': |
| 19 | + new Audio(genderSoundUK === 'm' ? audioENMale : audioENFemale).play(); |
| 20 | + genderSoundUK = genderSoundUK === 'm' ? 'f' : 'm'; |
| 21 | + break; |
| 22 | + } |
7 | 23 | } |
8 | 24 | </script> |
9 | 25 |
|
10 | | -<div class="mx-auto rounded-xl border-[.1px] border-accent p-4 text-center md:p-8 md:text-xl"> |
11 | | - <p> |
12 | | - <span class="flex flex-row justify-center gap-x-4"> |
13 | | - <span class="font-serif italic">/ˈkoːdəˌvoːɣəl/</span> |
14 | | - <button on:click={playSound} |
15 | | - ><Volume2 class="stroke-foreground/50 hover:stroke-foreground" /></button |
16 | | - ></span |
17 | | - > |
18 | | - A bird that enjoys programming. |
19 | | - </p> |
| 26 | +<div |
| 27 | + class="mx-auto flex flex-col items-center justify-center rounded-xl border-[.1px] border-accent p-4 text-center md:p-8 md:text-xl" |
| 28 | +> |
| 29 | + <span class="flex flex-col gap-x-4"> |
| 30 | + <span class="flex flex-col font-serif italic">/ˈkoːdəˌvoːɣəl/</span> |
| 31 | + </span> |
| 32 | + <p>A bird that enjoys programming.</p> |
| 33 | + <span class="mt-2 flex flex-row gap-x-4"> |
| 34 | + <button onclick={() => playSound('nl')} class="flex flex-row gap-x-1"> |
| 35 | + <Volume2 class="stroke-foreground/50 hover:stroke-foreground" /> |
| 36 | + <span> 🇳🇱</span> |
| 37 | + </button> |
| 38 | + <button onclick={() => playSound('en')} class="flex flex-row gap-x-1"> |
| 39 | + <Volume2 class="stroke-foreground/50 hover:stroke-foreground" /> |
| 40 | + <span> 🇬🇧 </span> |
| 41 | + </button> |
| 42 | + </span> |
20 | 43 | </div> |
0 commit comments