I'm working on a translator from text to Nato alphabet. I'm using tkinter to make a basic interface. I have a wav file for every letter of the Nato alphabet. I want it to play the file, but I can't find a good way to. I have a mac, so winsound doesn't work. Does anyone know a reasonably simple method to play those files?
-
4Possible duplicate of How to trigger from Python playing of a WAV or MP3 audio file on a Mac?Mohammad Athar– Mohammad Athar2018-04-17 14:14:08 +00:00Commented Apr 17, 2018 at 14:14
-
See stackoverflow.com/a/66598782/8925535droptop– droptop2021-03-16 19:56:41 +00:00Commented Mar 16, 2021 at 19:56
Add a comment
|
1 Answer
I would use PyGame on Mac, because of its portability.
If you really want to use mp3 try this code:
import pygame
pygame.mixer.pre_init(44100, -16, 2, 2048) # setup mixer to avoid sound lag
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load('your_mp3_file.mp3')
pygame.mixer.music.play(-1)
But, if I were you, I would prefer this simpler approach on a Mac:
from os import system
system('say Hello world!')