Hi everyone,
I've tried winsound (with wav instead), looks like is working but but produces no sound.
then I've tried without success to install playsound module and pygame module,
again, without success pip simply not execute anything.
Is a simple way to play an mp3 from a macro?
thanks!
cheers,
Dorin
[solved] How to play an mp3 from macro?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[solved] How to play an mp3 from macro?
Last edited by DorinDXN on Sun Jul 24, 2022 6:54 am, edited 1 time in total.
Re: How to play an mp3 from macro?
You can install PySide2 QtMultimedia package and use appropriate classes of it.
Re: How to play an mp3 from macro?
https://pypi.org/project/playsound/
single file - so could even copy instead of installing
at least that was the top result when searching the web...
or if that does not work there is always a system call to any audio player possible...
single file - so could even copy instead of installing
at least that was the top result when searching the web...
or if that does not work there is always a system call to any audio player possible...
Re: How to play an mp3 from macro?
Thanks for replies, here are my findings so far
for now I have to use winsound
unfortunately is not supported in FreeCAD 0.18 - Python 2.7.14
I'd preferred as FreeCAD 0.20 has full-screen issues on my PC (Win 7)
Code: Select all
import winsound
winsound.PlaySound("S:\\Sound\\1.wav", winsound.SND_FILENAME) # OK
winsound.PlaySound("S:\\Sound\\1.wav", winsound.SND_ASYNC) # OK
#wav only, works both only in Python 3.8.10
Code: Select all
from playsound import playsound
playsound("S:\\Sound\\1.mp3", True) # OK
playsound("S:\\Sound\\1.mp3", False) # Not Working
#works in Python 2.7.14 and Python 3.8.10, only 1st, not working in ASYNC mode, with 2nd param False
Code: Select all
from PySide2 import QtMultimedia
QtMultimedia.QSound.play("S:\\Sound\\1.wav") # no sound
# no sound, reports : using null output device, none available
unfortunately is not supported in FreeCAD 0.18 - Python 2.7.14
I'd preferred as FreeCAD 0.20 has full-screen issues on my PC (Win 7)
Re: How to play an mp3 from macro?
BTW, any way to have winsound working on FreeCAD 0.18 Python 2.7.14 ?
Re: How to play an mp3 from macro?
Solved for FreeCAD 0.18 Python 2.7.14 Win 7
copied mp3play folder from here
https://github.com/michaelgundlach/mp3play
in the folder with macros
then made voiceplay() function and works both sync and async ,
tested with this code
cheers,
Dorin
copied mp3play folder from here
https://github.com/michaelgundlach/mp3play
in the folder with macros
then made voiceplay() function and works both sync and async ,
tested with this code
Code: Select all
import time
from threading import Thread
import mp3play
def voiceplay(filename, async):
if async :
thread = Thread(target=voiceplay, args=(filename, False))
thread.start()
else:
voice = mp3play.load(filename)
voice.play()
time.sleep(voice.seconds())
voiceplay("S:\\Sound\\1.mp3", True) #async
voiceplay("S:\\Sound\\3.mp3", False)
Dorin