<commit_before>from __future__ import print_function

from time import sleep

import numpy as np
import scipy as sp
from scipy.integrate import simps

NUM_SAMPLES = 1024
SAMPLING_RATE = 44100.
MAX_FREQ = SAMPLING_RATE / 2
FREQ_SAMPLES = NUM_SAMPLES / 8
TIMESLICE = 100  # ms
NUM_BINS = 16

data = {'values': None}

try:
    import pyaudio

    def update_audio_data():
        pa = pyaudio.PyAudio()
        stream = pa.open(
            format=pyaudio.paInt16,
            channels=1,
            rate=SAMPLING_RATE,
            input=True,
            frames_per_buffer=NUM_SAMPLES
        )

        while True:
            try:
                raw_data  = np.fromstring(stream.read(NUM_SAMPLES), dtype=np.int16)
                signal = raw_data / 32768.0
                fft = sp.fft(signal)
                spectrum = abs(fft)[:int(NUM_SAMPLES/2)]
                power = spectrum**2
                bins = simps(np.split(power, NUM_BINS))
                data['values'] = signal, spectrum, bins
            except:
                continue

except:
    print()
    print(" *** Pyaudio package not installed, using synthesized audio data ***")
    print()
<commit_msg>pass SAMPLE_RATE as integer (#6758)<commit_after>from __future__ import print_function

from time import sleep

import numpy as np
import scipy as sp
from scipy.integrate import simps

NUM_SAMPLES = 1024
SAMPLING_RATE = 44100.
MAX_FREQ = SAMPLING_RATE / 2
FREQ_SAMPLES = NUM_SAMPLES / 8
TIMESLICE = 100  # ms
NUM_BINS = 16

data = {'values': None}

try:
    import pyaudio

    def update_audio_data():
        pa = pyaudio.PyAudio()
        stream = pa.open(
            format=pyaudio.paInt16,
            channels=1,
            rate=int(SAMPLING_RATE),
            input=True,
            frames_per_buffer=NUM_SAMPLES
        )

        while True:
            try:
                raw_data  = np.fromstring(stream.read(NUM_SAMPLES), dtype=np.int16)
                signal = raw_data / 32768.0
                fft = sp.fft(signal)
                spectrum = abs(fft)[:int(NUM_SAMPLES/2)]
                power = spectrum**2
                bins = simps(np.split(power, NUM_BINS))
                data['values'] = signal, spectrum, bins
            except:
                continue

except:
    print()
    print(" *** Pyaudio package not installed, using synthesized audio data ***")
    print()

{'fraction_non_alphanumeric': 0.08968421052631578, 'fraction_numerical': 0.026105263157894736, 'mean_word_length': 1.9515527950310558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5303961', 'n_tokens_mistral': 805, 'n_tokens_neox': 731, 'n_words': 180}