Python Forum
I am having a problem with my Slider
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am having a problem with my Slider
#1
I am trying to control the frequency sampling rate of my dial_tone python code through a Flask webserver. The audio output still works but when I drag the slider it doesnt affect the audio!


Here is my webserver script:

from flask import Flask
from flask import request
from dial_tone_modified import dial_tone_modified
app = Flask(__name__)

tb = dial_tone_modified()

@app.route("/set_samp_rate")
def set_samp_rate():
  samp_rate = request.args.get("samp_rate")
  print "Received " + str(samp_rate)

@app.route("/")

def web_interface():
  html = open("web_interface.html")
  response = html.read().replace('\n', '')
  html.close()
  return response


tb.start()


def main():

    return "Welcome to my Flask Page!"

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=8000)
And this is my dial_tone code:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Dial Tone Modified
# Generated: Mon Jul 15 11:15:28 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



class dial_tone_modified(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self, "Dial Tone Modified")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_0 = samp_rate_0 = 32000
        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, .4, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, .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 get_samp_rate_0(self, a=32000):
        self.samp_rate_0=a
        return

    def set_samp_rate_0(self, samp_rate_0):
        self.samp_rate_0 = samp_rate_0

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)


def main(top_block_cls=dial_tone_modified, options=None):

    tb = dial_tone_modified()
    tb.start()
    try:
        raw_input('Press Enter to quit: ')
    except EOFError:
        pass
    tb.stop()
    tb.wait()


if __name__ == '__main__':
    main()
And this is my html code:

<!DOCTYPE html>
<html>
<body>

<h1>Web Browser Control</h1>
<p>Drag the slider to display the current value.</p>

<div id="slidecontainer">
  <input type="range" min="0" max="32e3" value="0" id="range1">
  <p>Value: <span id="range1_value"></span></p>
</div>

<script>
var slider = document.getElementById("range1");
var output = document.getElementById("range1_value");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = slider.value;
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    }
  };
  xhttp.open("GET", "http://127.0.0.1:5000/set_samp_rate_0?samp_rate_0=" + slider.value, true);
  xhttp.send();
}

</script>

</body>
</html>
Can any one help me how to solve this problem, please!
Reply


Messages In This Thread
I am having a problem with my Slider - by Hadad - Jul-22-2019, 02:31 AM
RE: I am having a problem with my Slider - by Hadad - Jul-23-2019, 06:21 PM
RE: I am having a problem with my Slider - by Hadad - Jul-23-2019, 07:14 PM
RE: I am having a problem with my Slider - by Hadad - Jul-24-2019, 01:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using range slider in flask webpage to use in python KimPet 2 7,656 Jan-23-2021, 11:58 PM
Last Post: snippsat
  reduce volume slider to 0% metulburr 6 3,636 Jun-15-2019, 09:58 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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