Automatic Gain Control in Python?
Benjamin Schollnick
bschollnick at schollnick.net
Sun May 29 11:50:39 EDT 2022
Well, maybe a different approach might be better?
https://www.amazon.com/LEMONKTV-Control-Device-Karaoke-Machine/dp/B07H49JB8S <https://www.amazon.com/LEMONKTV-Control-Device-Karaoke-Machine/dp/B07H49JB8S>
I’m unclear on how bringing the audio track into a computer to examine detect the audio level, and then adjusting the volume out of the Smart Speaker is really doing more than adding complexity.
An all analog solution might be the better route, although finding something that is inexpensive might be an issue as well.
- Benjamin
> On May 29, 2022, at 11:32 AM, Steve GS <Gronicus at SGA.Ninja> wrote:
>
> No, not a digital file. I am playing the podcast/broadcast live to the community using a separate network of smart speakers (Amazon Echo). Commands are being sent hourly through a speaker to the SS from an excel program. I want to monitor the audio level between the line-out of the SS and the input to another computer which then records the audio using Audacity for a single replay during the week.
>
> I think my first post should have started “Fasten your seat belts, it is going to be a bumpy night…)
>
>
> Genie: You have three wishes.
> Me: I wish I had more wishes.
> Genie: You cannot wish for more wishes.
> Me: I wish I could.
>
> From: Benjamin Schollnick <bschollnick at schollnick.net <mailto:bschollnick at schollnick.net>>
> Sent: Sunday, May 29, 2022 11:18 AM
> To: Steve GS <Gronicus at SGA.Ninja <mailto:Gronicus at SGA.Ninja>>
> Cc: Richard Damon <Richard at Damon-Family.org <mailto:Richard at Damon-Family.org>>; Python <python-list at python.org <mailto:python-list at python.org>>
> Subject: Re: Automatic Gain Control in Python?
>
> Okay, you are capturing the audio stream as a digital file somewhere, correct?
>
> Why not just right a 3rd party package to normalize the audio levels in the digital file? It’ll be faster, and probably easier than trying to do it in real time…
>
> eg. https://campus.datacamp.com/courses/spoken-language-processing-in-python/manipulating-audio-files-with-pydub?ex=8 <https://campus.datacamp.com/courses/spoken-language-processing-in-python/manipulating-audio-files-with-pydub?ex=8>
>
>> Normalizing an audio file with PyDub
>>
>> Sometimes you'll have audio files where the speech is loud in some portions and quiet in others. Having this variance in volume can hinder transcription.
>> Luckily, PyDub's effects module has a function called normalize() which finds the maximum volume of an AudioSegment, then adjusts the rest of the AudioSegment to be in proportion. This means the quiet parts will get a volume boost.
>> You can listen to an example of an audio file which starts as loud then goes quiet, loud_then_quiet.wav, here <https://assets.datacamp.com/production/repositories/4637/datasets/9251c751d3efccf781f3e189d68b37c8d22be9ca/ex3_datacamp_loud_then_quiet.wav>.
>> In this exercise, you'll use normalize() to normalize the volume of our file, making it sound more like this <https://assets.datacamp.com/production/repositories/4637/datasets/f0c1ba35ff99f07df8cfeee810c7b12118d9cd0f/ex3_datamcamp_normalized_loud_quiet.wav>.
> or
>
> https://stackoverflow.com/questions/57925304/how-to-normalize-a-raw-audio-file-with-python <https://stackoverflow.com/questions/57925304/how-to-normalize-a-raw-audio-file-with-python>
>
>
>
> - Benjamin
>
>
>> On May 29, 2022, at 11:04 AM, Steve GS <Gronicus at SGA.Ninja <mailto:Gronicus at SGA.Ninja>> wrote:
>>
>>>> From your description, your fundamental problem is you are trying to automatically "control" things that weren't designed to be automatically controlled in the way you are attempting.
>>
>> How so? I am sending commands to a smart speaker and it plays podcasts and broadcasts.
>> How is this a violation of SS design?
>>
>> ===================
>>
>>>> The smart speaker assumes the "user" will adjust the volume either with the controls or with verbal commands, So things will be a bit "clunky" in your results as you command the smart speaker volume level.
>>
>> So, you want me to sit here for every hour of the weekend and monitor the audio levels for a result that will get, at best, one replay when I believe it can be automated.
>>
>> ===================
>>
>>>> Yes, you have an automated system that does most of what you want, but it is based on pieces not designed to be automated in this way, and you are running into the limitations caused by that.
>>
>> Again, what limitations of the SS am I violating? It is designed to receive commands and play the audio.
>> Also, what makes you think that you know how my program is based?
>>
>> ===================
>>
>>>> Yes, you could split the aux-out to bring it into another computer to listen to the sound level, and then using a sound input package get samples of what is playing, and analyze that data to get an average volume, and then issues the command to adjust the volume level.
>>
>> Hmmm, is that not my original question? Are you suggesting to monitor the audio, sense it for volume changes and apply those changes to the original audio? One thing that may have to happen is a timed-delay to all for the AGC to work. This may require a correlation circuit.
>>
>> ==================
>>
>>>> What you seem to be missing is that you could get the podcasts from a browser, and all a browser is is a program. It isn't that much work to write a rudimentary browser in python, especially if you don't actually need to display the results to a user, but are only trying to automate a particular task.
>>
>> Writing my own browser in Python might work. Do you have a sample one that I could twerk to fit my needs?
>> I would have to be able to invoke it and an hour later devoke it least I end up with multiple audio channels playing.
>>
>> Either way, I would still need an AGC program which was my original question.
>>
>> ===================
>>
>>>> You seem to feel strongly invested in your current code base, which is understandable, but it seems you have reached a point where you don't want to live with the limitations CAUSED by that system.
>>
>> The changes in volume are not CAUSED by my program. The want to fix them is a new development to improve the product. The volume fluctuations are causes, or neglections, by the engineers at the sources of podcasts and broadcasts.
>>
>>
>>>> Yes, there is likely a way to tack on another layer of "stuff" to adjust for this issue, but it likely is going to require some real programming.
>>
>>
>>>> It may well be the design I am suggesting, of writing a program to fetch the podcast and save it requires a bit more work to get to the level you currently are at, but the results are a system that is actually designed to be controlled by automation. Maybe it is beyond you ability, but then so might the programming to get the volume.
>>
>> "Real programming"?, REAL PROGRAMMING? Well at this I have to say "Well duh". I have more than 40 years of programming in languages including assembly, Pascal, C, C++, BASIC, Visual BASIC, COBOL, VBA and Python for starters. I even dipped into AT&T's SNOBAL. Starting in the mid-80s, I taught Visual BASIC and VBA for 15 years in high school and at the University level.
>>
>> I have 2000 lines of code of Python that helped me to bring my A1c reading from 9.0 to 6.1 thank you. I have a program of similar size that tracks the 450 specific plants in my garden. It even monitors degree-days to help me know when certain insects attack and when to tend to individual needs. This Excel/Jukebox program is also about 2000 lines of code. (Seems to be a pattern here). All of these programs are decorated with numerous pops and whistles that make programming and use quite pleasurable,
>>
>> So, do you I think I am now ready for some "real programming".
>>
>> ===================
>>
>>>> I will also add, that the way your describe going to your "community"
>> gives me questions if this is a violation of copyright. Maybe it is something you can "Get away with", but I am not sure what you are doing is actually legitimate.
>>
>> Yes, I have been through that. It is totally legal to record NPR broadcasts for replay as long as they are not retained for than a month or for multiple replays. Your suggestion to download and play a podcast or broadcast is legal only for live replay. My want to record them for one replay for my own use. Personal play is a different story.
>>
>>
>>
>>
>> -----Original Message-----
>> From: Richard Damon <richard.damon at gmail.com <mailto:richard.damon at gmail.com>> On Behalf Of Richard Damon
>> Sent: Sunday, May 29, 2022 8:03 AM
>> To: Steve GS <Gronicus at SGA.Ninja <mailto:Gronicus at SGA.Ninja>>; Python <python-list at python.org <mailto:python-list at python.org>>
>> Subject: Re: Automatic Gain Control in Python?
>>
>> From your description, your fundamental problem is you are trying to automatically "control" things that weren't designed to be automatically controlled in the way you are attempting.
>>
>> The smart speaker assumes the "user" will adjust the volume either with the controls or with verbal commands, So things will be a bit "clunky"
>> in your results as you command the smart speaker volume level.
>>
>> Yes, you have an automated system that does most of what you want, but it is based on pieces not designed to be automated in this way, and you are running into the limitations caused by that.
>>
>> Yes, you could split the aux-out to bring it into another computer to listen to the sound level, and then using a sound input package get samples of what is playing, and analyze that data to get an average volume, and then issues the command to adjust the volume level.
>>
>> What you seem to be missing is that you could get the podcasts from a browser, and all a browser is is a program. It isn't that much work to write a rudimentary browser in python, especially if you don't actually need to display the results to a user, but are only trying to automate a particular task.
>>
>> You seem to feel strongly invested in your current code base, which is understandable, but it seems you have reached a point where you don't want to live with the limitations CAUSED by that system. Yes, there is likely a way to tack on another layer of "stuff" to adjust for this issue, but it likely is going to require some real programming.
>>
>> It may well be the design I am suggesting, of writing a program to fetch the podcast and save it requires a bit more work to get to the level you currently are at, but the results are a system that is actually designed to be controlled by automation. Maybe it is beyond you ability, but then so might the programming to get the volume.
>>
>> I will also add, that the way your describe going to your "community"
>> gives me questions if this is a violation of copyright. Maybe it is something you can "Get away with", but I am not sure what you are doing is actually legitimate.
>>
>> On 5/29/22 1:09 AM, Steve GS wrote:
>>
>>> You really need to understand what I am trying to do.
>>> It is not a simple lesson in use of podcasts.
>>> This is an automated system. I call it my NPR Jukebox.
>>>
>>> 15 years ago, I started with hourly URL calls to a browser to record specific NPR programs. It took a lot of coordination. I had to use IE because I needed to start and stop browsers on the hour and IE was the only one that could do that. Then web sites started "upgrading" to Edge. Through some trickery I was able to get Edge to do what IE did but it was unstable.
>>>
>>> I then discovered the Echo Smart Speaker. I set my program to announce the broadcast station or podcast by speaker to the smart speaker and it cured a lot of headaches. I then was able to call podcasts because the Echo handles them through TuneIn. Unfortunately, not all broadcasts ae available as podcasts.
>>>
>>> I am not here diddling around just playing podcasts. Let me repeat
>>> what I have already said. It is an automated system. Every hour for
>>> 48 hours on every weekend, my system using a well-developed Excel/VBA
>>> program that vocally talks to the SS hourly. The SS finds the audio
>>> and sends it to my Audacity recorder on another computer through
>>> aux-out to mic-in cable. The selections of audio are also transmitted
>>> to the community at the time of recording
>>>
>>> That part of the system is almost flawless, well compared to that I had before. Although the quality, tone, and timing of the announcement, the SS still gets confused once in a while and goes silent for the hour. I need to detect this too.
>>>
>>> Ok, now back to the original question.
>>>
>>> Podcasts and broadcasts apparently do not use the Dolby tone to balance the audio levels. And I receive highly fluctuating levels of audio. Sometimes it is between sides of a conversation, sometimes it is the podcast vs station identifications, then it is great differences between one web site and another. Then there's the differences with male and female voices. Imagine that you are watching TV late night then the commercials COME IN AT FULL BLAST.
>>>
>>> The technology of the industry grew up with male voices and apparently sees no reason to adjust for female. I have worked with audio systems and making recordings for more years that I want to admit.
>>>
>>> All I want is software to detect level changes over time and attempt to equalize them.
>>> It has to be work between the SS and the recorder and is to be checking all the time.
>>>
>>> The code is to: Listen to the audio level for about 10 seconds or so and raise or lower the level in small increments.
>>> It has nothing to do with understanding how to grab podcasts. The system is working very well for that.
>>>
>>>
>>> Footnote:
>>> “What rhymes with orange?”
>>> “No, it doesn’t..”
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: Richard Damon <richard.damon at gmail.com <mailto:richard.damon at gmail.com>> On Behalf Of Richard
>>> Damon
>>> Sent: Saturday, May 28, 2022 11:37 PM
>>> To: Steve GS <Gronicus at SGA.Ninja <mailto:Gronicus at SGA.Ninja>>
>>> Subject: Re: Automatic Gain Control in Python?
>>>
>>> On 5/28/22 8:17 PM, Steve GS wrote:
>>>
>>>> "My first thought is you are solving the wrong problem. What seems a
>>>> better option would be to get your code to actually connect up to the
>>>> podcast and just download the audio directly, rather than trying to
>>>> get the smart speaker to play the audio and record it with a microphone."
>>>>
>>>> The smart-speaker is bringing in the podcast by hourly automated
>>>> commands and sending by audio cable to a computer which is recording
>>>> it with Audacity. This is an automated system that runs for 48 hours every weekend.
>>>> Its output is played live throughout the facility and is also
>>>> recorded for replay through the week.
>>>>
>>>> No download to use.
>>>>
>>>> AGC is to happen when the Smart Speaker is playing it, real time.
>>>> Any post-record editing would be a horrendous task to say the least.
>>>>
>>> My guess is you don't understand how "Podcasts" work. All they are is a web resource that your Browser/Smart Device makes a request off, and the contents are streamed over the internet to that device, which then plays it. Smart Speakers just have a program that knows how to access these.
>>>
>>> Since they can be listened to on a web browser, a program can download the data. They might be doing things to make this harder, but that is a sign that you shouldn't be doing this in the first place.
>>>
>>> Often, the data format that is streamed is exactly like the file format for storing an audio file (since that is what the code in the browser is built to handle).
>>>
>>> It may be a bit of work to figure out the access methods to get the data, but this is the sort of job that computers were designed to do.
>>> Trying to make things that weren't designed to be remote controlled to be remote controlled may well be a lot more work.
>>>
>>> --
>>> Richard Damon
>>>
>>
>> --
>> Richard Damon
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list <https://mail.python.org/mailman/listinfo/python-list>
More information about the Python-list
mailing list