Home Audio filter with python
Reply: 0

Audio filter with python

user43415 Published in September 21, 2018, 8:04 am

As part of an interactive installation, I would like to program an audio filter LPF (cut high frequencies) on a sound that runs in a loop on python. In addition I would like to vary the cutoff frequency of the filter according to the distance of an obstacle measured by a distance sensor, all on a Raspberry Pi 3.

I have already managed to program the distance measurement by the sensor and to run a looping sound but I do not know how to do it for the audio filter. By searching on the internet I can not find an answer and a clear method on my situation.

Here is my code:

 import RPi.GPIO as GPIO
 import time
 import pygame
 caca = pygame.mixer.Sound("bells001.wav")

 #set GPIO Pins

 #set GPIO direction (IN / OUT)

 def distance():
 # set Trigger to HIGH
 GPIO.output(GPIO_TRIGGER, True)

 # set Trigger after 0.01ms to LOW
GPIO.output(GPIO_TRIGGER, False)

StartTime = time.time()
StopTime = time.time()

# save StartTime
while GPIO.input(GPIO_ECHO) == 0:
    StartTime = time.time()

# save time of arrival
while GPIO.input(GPIO_ECHO) == 1:
    StopTime = time.time()

# time difference between start and arrival
TimeElapsed = StopTime - StartTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance = (TimeElapsed * 34300) / 2

return distance

if __name__ == '__main__':
    while True:
        dist = distance()
        print (dist)

    # Reset by pressing CTRL + C
except KeyboardInterrupt:
    print("Measurement stopped by User")

I tried this for now

from pydub import AudioSegment
from pydub.playback import play

song = AudioSegment.from_wav("bells001.wav")
new = song.low_pass_filter(10000)

Unfortunately instead of me out a filtered sound, I have the sound very degraded with lots of crunches ... Anyone have an idea?

I tried other scripts but I still have problems with module or library not found while I install and reinstall all these modules.

Can anyone help me?

share|improve this question
  • IF you have a problem with module or library not found, you have to find that library, or remove parts of the code that are causing the problem. Which part has a problem, song.low_pass_filter? – VladP Feb 14 at 14:54

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48743539%2faudio-filter-with-python%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged python-3.x audio filter or ask your own question.

StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|python-3.x|audio|filter|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.575748 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO