Python Forum
wbserver roundSlider widget doesn't start/update audio tone program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wbserver roundSlider widget doesn't start/update audio tone program
#1
When I run my webserver program the audio output is working (which is continuous Tone)and the Slider works too (I mean the Slider does update the values). But the problem is this Slider widget doesn't have any control over my frequency value (which determines the Tone sound)! Both of them (Slider and Audio Tone) are working but sounds like they don't communicate with each other.


Kindly, I need your help to guide to what I am doing wrong here.


Here is an image about how it looks when values are live updated when I move the slider:

[Image: QnRj3G.png]

Here is my Flask webserver code (thats where I run my app.py from through the Terminal):

    from flask import Flask, render_template, jsonify, request, redirect, url_for
    from random import randint
    from top_block_22 import top_block_22
    
    tb = top_block_22()
    tb.start()
    
    app = Flask(__name__)
    @app.route('/')
    def slide_func():
        return render_template("index.html")
    
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5000, debug=True)
And this is my Audio tone python code (which is generated from gnuradio software):

    #!/usr/bin/env python2
    # -*- coding: utf-8 -*-
    ##################################################
    # GNU Radio Python Flow Graph
    # Title: Top Block 22
    # Generated: Tue Jul 23 15:54:16 2019
    ##################################################
    
    
    from gnuradio import analog
    from gnuradio import audio
    from gnuradio import blocks
    from gnuradio import eng_notation
    from gnuradio import gr
    from gnuradio.eng_option import eng_option
    from gnuradio.filter import firdes
    from optparse import OptionParser
    from flask import Flask, render_template, jsonify, request, redirect, url_for
    from random import randint
    
    
    app = Flask(__name__)
    @app.route('/')
    def slide_func():
            return render_template("index.html")
    @app.route('/valueofslider')
    def slide():
        slide_val = request.args.get('slide_val')
        return top_block_22(slide_val)     
    
    
    
    class top_block_22(gr.top_block):
    
    
        def __init__(self, slide_val):
    
            self.slide_val = slide_val
    
            #gr.top_block.__init__(self, "Top Block 22")
            gr.top_block.__init__(self, "Top Block 22")        
            ##################################################
            # Variables
            ##################################################
            self.samp_rate = samp_rate = 32000
    
            ##################################################
            # Blocks
            ##################################################
            self.blocks_add_xx = blocks.add_vff(1)
            self.audio_sink = audio.sink(32000, '', True)
            self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, 0.4, 0)
            self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, 0.4, 0)
            self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)
    
            ##################################################
            # Connections
            ##################################################
            self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
            self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
            self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
            self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
    
    
    def main(top_block_cls=top_block_22, options=None):
    
        tb = top_block_cls()
        tb.start()
    
        try:
            raw_input('Press Enter to quit: ')
        except EOFError:
            pass
        tb.stop()
        tb.wait()
      
        samp_rate = int(slide_val) + 40000
        print(samp_rate)
        return(slide_val) # Still need to return or get TypeError 
     
    if __name__ == '__main__':
        app.run(debug=True)
Reply
#2
I have a "dial tone" python program that is imported into a Falsk webserver, and I have an html embedded roundSlider widget that I am trying to use to update the sample rate variable values inside dial tone program. Once I run the webserver and start dragging the slider, visually the value of the slider does update/change when dragging it, but there is no tone, the tone program doesn't start!

Please, I need your help to figure this out.

Here is my flask app.py:

from flask import Flask, render_template, jsonify, request,redirect,url_for
    from random import randint
    from top_block_22 import top_block_22
      
    app = Flask(__name__)
    # def test():
    #     print("its working") 
    @app.route('/')
    def slide_func():
        return render_template("index.html")
        print(slide_val)
        return(slide_val)
    def test():
        print("its working")
    
    @app.route('/valueofslider')
    def slide():
        slide_val = request.args.get('slide_val')
        return main(slide_val)   
    
    def main(slide_val):
    
        tb = top_block_22()
        tb.start()
        samp_rate = int(slide_val) + 100
        print(samp_rate)
        return(slide_val)  
        app.debug = True
    if __name__ == '__main__':
        app.run(debug=True)
Main dial tone code:

from gnuradio import analog
from gnuradio import audio

    from gnuradio import blocks
    from gnuradio import eng_notation
    from gnuradio import gr
    from gnuradio.eng_option import eng_option
    from gnuradio.filter import firdes
    from optparse import OptionParser
    from flask import Flask, render_template, jsonify, request, redirect, url_for
    from random import randint
    #from app import *
    
       
    
    
    
    class top_block_22(gr.top_block):
    
        def __init__(self, samp_rate):

            gr.top_block.__init__(self, "Top Block 22")        
            ##################################################
            # Variables
            ##################################################
            self.samp_rate = samp_rate = 32000
    
            ##################################################
            # Blocks
            ##################################################
            self.blocks_add_xx = blocks.add_vff(1)
            self.audio_sink = audio.sink(32000, '', True)
            self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, 0.4, 0)
            self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, 0.4, 0)
            self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)
    
            ##################################################
            # Connections
            ##################################################
            self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
            self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
            self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
            self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
    
       
    
    def main(top_block_cls=top_block_22, options=None):
       
     
        tb = top_block_22('samp_rate')
        
        tb.start()
        try:
            raw_input('Press Enter to quit: ')
        except EOFError:
            pass
        tb.stop()
        tb.wait()
    
    
    if __name__ == '__main__':
            main()
index.html script:

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>jQuery roundSlider - JS Bin</title>
      <link rel="icon" href="data:,">
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>
    </head>
    <body>
      <!-- Only html needed   -->
    <form class="form-inline" method="POST" action="{{ url_for('slide') }}">
      <div id="slider"></div>
    
      <script>
        var val;
        $("#slider").roundSlider({
          radius: 215,
            min: 0,
            max: 100000,
           change: function () {
    
            var obj1 = $("#slider").data("roundSlider");
            val = obj1.getValue();
            value: 10
            $.getJSON('/valueofslider', {
              slide_val: val
            });
          }
        });
      </script>
    </body>
    </html>
Here is an image of the slider when its updating its values:

[Image: MEc6Qv.png]
Reply
#3
how this thread is different from your other thread?
https://python-forum.io/Thread-A-problem...sk-Webserv
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Aug-01-2019, 03:50 PM)buran Wrote: how this thread is different from your other thread?
It is different because in the other thread I start by saying: When I run my webserver program the audio output is working...
while this time audio in not working.
Reply
#5
To be honest it looks the same problem - how to control your "dial tone script" from the slider. In the other thread you start the dial tone script and it worked, but you were not able to get value from the slider. here you capture the changing value from the slider and not able to affect the script accordingly. i.e. what you ultimately want is to link the slider and the dial tone script right? so I will merge both
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Aug-01-2019, 04:02 PM)buran Wrote: I will merge both

I am not a real coder and definitely won't argue with knowledgable geeks like you! You are the boss here Buran :) but I hope it will still show as a newly posted thread right?
It is just devastating for me, struggling without knowledge and less help around.

(Aug-01-2019, 04:08 PM)Hadad Wrote: I will merge both
You made it look so messy and confusing!
If the problem is slightly different doesn't mean its the same!!!
Reply
#7
I will let other team members decide if it is messed or not.
Your problem, simple and clear:
1. run "dial tone script" and play sound to user (note that in your first script you play the script locally i.e. you hear it because you run the webserver on the same computer, if it is hosted somewhere you will not here the sound when browse the page)
2. control the "dial tone script" frequency from a slider.

What you have posted so far - two different unsuccessful attempts to accomplish your goal. You are messing with the same code, again - unsuccessfully. Both threads are clearly connected/related. So it is warranted to merge them.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Also this was the original Thread where i made code for slider,as you have made many Thread about this.
As mention before you have a project that's not so easy,and i have not have time to install GNU Radio to test all,and that's really not my task either.

You probably need some Threading code as there are two things happening at once live Flask server(run live) with Ajax return of values, GNU Radio(run live),this usually mean that there will be a block.
Reply
#9
(Aug-01-2019, 05:32 PM)snippsat Wrote: a project that's not so easy
I just gave up now on accomplishing this task this way, too much for a dumb beginner like me! I will try a different route to accomplish this project. I read somewhere about building a JS slider then...... don't know how, but will keep fighting till I get it.

(Aug-01-2019, 05:00 PM)buran Wrote: I will let other team members decide if it is messed or not.
You may forget about it, I just gave up!
Reply


Forum Jump:

User Panel Messages

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