0

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?

Nat
  • 55
  • 1
  • 10
  • 4
    Possible duplicate of [How to trigger from Python playing of a WAV or MP3 audio file on a Mac?](https://stackoverflow.com/questions/3498313/how-to-trigger-from-python-playing-of-a-wav-or-mp3-audio-file-on-a-mac) – Mohammad Athar Apr 17 '18 at 14:14
  • See https://stackoverflow.com/a/66598782/8925535 – droptop Mar 16 '21 at 19:56

1 Answers1

2

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!')
Pitto
  • 8,229
  • 3
  • 42
  • 51