Bottom Page

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:

İmage


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)

Quote
#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:

İmage
Quote
#3
how this thread is different from your other thread?
https://python-forum.io/Thread-A-problem...sk-Webserv
Quote
#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.
Quote
#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
Quote
#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!!!
Quote
#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.
Quote
#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.
Quote
#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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  instant update of graph within selected time range brecht83 0 409 Sep-24-2018, 01:34 PM
Last Post: brecht83
  How to start learning Python? SmartGrid 2 647 Aug-17-2018, 11:32 AM
Last Post: metulburr
  Super simple import doesn't work. Please help! Mustey 9 1,155 Jul-27-2018, 09:52 AM
Last Post: Mustey
  http.server start delay pastacolsugo 1 817 Apr-18-2018, 08:58 PM
Last Post: micseydel
  flask, I want to send a json from the front end and update it to the postgresql DB wi passion044 1 1,151 Apr-12-2018, 08:40 AM
Last Post: thomasp
  Update records in table liee 1 799 Feb-07-2018, 09:59 AM
Last Post: ka06059
  Scripted update of web page treatitwell 6 1,174 Jan-06-2018, 02:21 PM
Last Post: snippsat
  realtime database update in django x64 2 2,097 Aug-09-2017, 05:22 PM
Last Post: nilamo
  Start at python Networkin Grean 5 2,581 Feb-09-2017, 02:25 PM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)