G
G
Grishan Trudovik2019-08-17 14:17:07
Python
Grishan Trudovik, 2019-08-17 14:17:07

How to write a random sound generator in python?

I recently started getting interested in Python.
You need to write a code that, when run, the speakers will play tonal sounds, peaks, buzz.
So that you can set the playback time of the "track", for example, to 3 minutes or 30.
To be able to set the range from which the key or length of the "note" will be randomly selected.
Without connecting samples.
Where do I begin? Does anyone have any ready made solutions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Web Dentist, 2019-08-17
@kgb_zor

Something like this

import winsound
from random import randint
from time import sleep

MAX_FREQUENCY = 2500  # Максимальная частота звука 2500Гц
MAX_DURATION = 1000  # Максимальное время для озвучки одного сигнала 1000 ms


def generate_random_beeps(minutes):
    for _ in range(minutes * 60):
        frequency = randint(1, MAX_FREQUENCY)
        duration = randint(1, MAX_FREQUENCY)
        winsound.Beep(frequency, duration)
        sleep(1)

S
sash999, 2019-08-17
@sash999

for _ in - please explain to the non-Pythonist what _ means here. Senks ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question