![]() |
|
[Tut] This is How I Played a Sinus Tone in My Jupyter Notebook (Python) - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] This is How I Played a Sinus Tone in My Jupyter Notebook (Python) (/thread-100432.html) |
[Tut] This is How I Played a Sinus Tone in My Jupyter Notebook (Python) - xSicKxBot - 12-19-2022 This is How I Played a Sinus Tone in My Jupyter Notebook (Python) 5/5 – (1 vote) What/Why? I want to write a simple Python script that warns me if crypto price data (e.g., BTC) crosses a certain threshold. This can be useful for trading or some other apps, so I thought it would be fun to do it. The tutorial in front of you simply documents my learnings on creating a sinus tone in my Jupyter Notebook—so it may benefit you as well. If you want the whole tutorial on my mini project, you can check it out here on the Finxter blog: Recommended Tutorial: I Made a Python Script That Beeps When BTC or ETH Prices Drop![]() Challenge Challenge: Write Python code in a Jupyter Notebook that creates a sinus tone when executed.Solution The easy way to solve this challenge is the following. ![]() This code creates a sine wave with a frequency of 500 Hz and plays it in the IPython environment. The wave is created using the NumPy library by specifying the frequency and the length of the wave (15000*2). The rate of the wave is set to 10000 Hz and autoplay is set to Code: TrueCode: import numpy as np
from IPython.display import Audio # Create the tone as a NumPy Sinus Wave
wave = np.sin(2*np.pi*500*np.arange(15000*2)/15000) # Play the Sinus Wave (tone)
Audio(wave, rate=10000, autoplay=True)This generates the following beep sound in your Jupyter Notebook: https://blog.finxter.com/wp-content/uploads/2022/12/peep.mp3 What happens if you change the Code: rateCode: Audio()Code: # Play the Sinus Wave (tone)
Audio(wave, rate=20000, autoplay=True)The beep sound tone gets higher: https://blog.finxter.com/wp-content/uploads/2022/12/beep_20000.mp3 You can play around with the Jupyter notebook here: ![]() But what if you don’t have a Jupyter notebook but a normal Python script (Win/Linux/macOS)? In that case, you cannot use the Code: IPython Recommended Tutorial: How to Make a Beep Sound in Python?Thanks for Reading! ![]() You’re welcome to join our free email academy where I share all our coding projects and cheat sheets on a weekly basis: |