Python Forum
Play fixed frequency sound in python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Play fixed frequency sound in python 3
#1
I would just like to play a fixed frequency for a fixed period of time to the default speakers (HDMI or other) on a RP3 running wheezy with eventual porting to RPI 4 on Buster. This is from within a python 3 program. I am not playing anything from a file - just outputting a tone to the speaker.

Because the development work is not done directly on a Pi, I'd prefer a solution that is not restricted to a Pi but could run on other Linux systems (I have PCs running Ubuntu 18 and Debian Buster). Running on Windows is NOT a requirement.

There seems to be lots of different libraries and many of them are really designed to output files rather than "play this tone for a fixed period of time". Starting a tone unblocked, then sleeping for the required time, then stopping the tone (like audiere - now obsolete) seems to be one simple way, given there is no single call to output for a fixed time.

Can someone suggest a library that has such simple features and point me in the right direction?
Reply
#2
I have not researched this on python 3,
but micropython (eg. on the micro:bit) has a built-in music module.
It does exactly what you want:
music.pitch(440, 1000) means play 440 herz for 1 second.

paul
Reply
#3
(Feb-07-2021, 06:20 PM)DPaul Wrote: I have not researched this on python 3,
but micropython (eg. on the micro:bit) has a built-in music module.
It does exactly what you want:
music.pitch(440, 1000) means play 440 herz for 1 second.

paul
Choice of device is not an option. I have already written a bunch of software for this and another application that run on the same Pi.

However, what showed up among related topics is a question like mine and the solution to it was to use pysine, an equally efficient option.

I imported pysine but even though I did not add any code to use it, I got this when running the program:
Error:
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 1,839 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Fixed colum width for rowLabels i Matplotlib pandabay 0 418 Jun-10-2023, 03:40 PM
Last Post: pandabay
  How can I send a .mp3 to play through my mic? ejected 20 20,161 Sep-01-2022, 02:38 AM
Last Post: victormayer
  Encrypt and decrypt in python using own fixed key SriRajesh 3 4,793 Feb-20-2022, 01:18 PM
Last Post: dboxall123
  Play the next music in a list Pymax 0 1,198 Jul-28-2021, 07:27 PM
Last Post: Pymax
  Image to Sound Python Project ankitdixit 1 2,605 Jul-26-2021, 08:20 PM
Last Post: snippsat
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,952 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  Referencing a fixed cell Mark17 2 2,051 Dec-17-2020, 07:14 PM
Last Post: Mark17
  how do i play an mp3 from a list gr3yali3n 3 2,122 Dec-01-2020, 08:50 AM
Last Post: Axel_Erfurt
  Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable kmarien 3 3,633 Nov-30-2020, 04:10 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020