示例#1
0
    def synthesize(self, command: str) -> None:
        # Parse command
        command_parser = CommandParser()
        parsed_command = command_parser.parse_command(command)

        # Create model of given word
        analyzer = Analyzer(self.sampling_frequency, self.frame_length, self.overlap, self.pre_emphasis)
        model = analyzer.analyze(parsed_command)

        # Create base signal generator
        print('Synthesizing command "' + parsed_command + '"...')
        base_signal_generator = BaseSignalGenerator(self.sampling_frequency)

        # Synthesize all frames (generate base signal + filter)
        dft_frames = list()
        for frame in model.frames:
            # Generate base signal
            if frame.base_frequency == 0:
                base_signal = base_signal_generator.generate_white_noise(model.get_frame_length())
            else:
                base_signal = base_signal_generator.generate_pulses(model.get_frame_length(), frame.base_frequency)
            base_signal_dft = fft(base_signal)

            # Filtration
            dft_frames.append(base_signal_dft*frame.energies)

        # Merge all frames using overlap-add technique
        synthesized_signal = np.array(np.real(idft(dft_frames[0])) * analyzer.hamming_window)
        window_signal = analyzer.hamming_window
        for i in range(1, len(dft_frames)):
            synthesized_signal = np.concatenate([synthesized_signal, np.zeros(self.hop)])
            window_signal = np.concatenate([window_signal, np.zeros(self.hop)])
            synthesized_signal[i*self.hop:i*self.hop+self.frame_length] += np.real(idft(dft_frames[i])) * analyzer.hamming_window
            window_signal[i*self.hop:i*self.hop+self.frame_length] += analyzer.hamming_window

        # Make sure not to divide by zero
        for i in range(len(window_signal)):
            if 0.1 > window_signal[i] > -0.1:
                if window_signal[i] >= 0:
                    window_signal[i] = 0.1
                else:
                    window_signal[i] = -0.1

        # Divide signal by windows to remove buzzing
        synthesized_signal = synthesized_signal/window_signal

        # De-emphasis
        for i in range(1, len(synthesized_signal)):
            synthesized_signal[i] += self.pre_emphasis*synthesized_signal[i-1]

        # Normalize signal
        synthesized_signal /= np.max(synthesized_signal)

        # Plot and save to file
        plt.plot(synthesized_signal)
        plt.title('Synthesized signal')
        plt.xlabel('Time [samples]')
        plt.ylabel('Amplitude')
        plt.show()
        scipy.io.wavfile.write('output.wav', self.sampling_frequency, synthesized_signal)
示例#2
0
    def _check_docker_by_container_id(item):
        analyzer = Analyzer()
        # -- Evaluates the docker image
        evaluated_docker_image = analyzer.evaluate_image(None, item['container_id'])

        # -- Updates mongodb report
        InternalServer.get_mongodb_driver().update_docker_image_scan_result_to_history(item['_id'],
                                                                                       evaluated_docker_image)
示例#3
0
    def _check_docker_by_container_id(item):
        analyzer = Analyzer()
        # -- Evaluates the docker image
        evaluated_docker_image = analyzer.evaluate_image(None, item['container_id'])

        # -- Updates mongodb report
        InternalServer.get_mongodb_driver().update_docker_image_scan_result_to_history(item['_id'],
                                                                                       evaluated_docker_image)
示例#4
0
    def _check_docker_by_image_name(item):
        analyzer = Analyzer()
        # -- Evaluates the docker image
        evaluated_docker_image = analyzer.evaluate_image(item['image_name'], None)

        # -- Updates mongodb report
        InternalServer.get_mongodb_driver().update_docker_image_scan_result_to_history(item['_id'],
                                                                                       evaluated_docker_image)

        # -- Cleanup
        if item['pulled']:
            InternalServer.get_docker_driver().docker_remove_image(item['image_name'])
示例#5
0
    def _check_docker_by_image_name(item):
        analyzer = Analyzer()
        # -- Evaluates the docker image
        evaluated_docker_image = analyzer.evaluate_image(item['image_name'], None)

        # -- Updates mongodb report
        InternalServer.get_mongodb_driver().update_docker_image_scan_result_to_history(item['_id'],
                                                                                       evaluated_docker_image)

        # -- Cleanup
        if item['pulled']:
            InternalServer.get_docker_driver().docker_remove_image(item['image_name'])
def init_process(model_path, needs_patches, device):
    global analyzer
    current_process = multiprocessing.current_process()
    process_name = current_process.name
    if device == "@numpy":
        device_id = -1
    else:
        device_id = int(process_name.split('-')[-1]) - 1
    analyzer = Analyzer(model_path, device_id, needs_patches=needs_patches)
示例#7
0
文件: agent.py 项目: zigmax/dagda
class Agent:

    # -- Public methods

    # Agent Constructor
    def __init__(self, dagda_server_url):
        super(Agent, self).__init__()
        self.dagda_server_url = dagda_server_url
        self.analyzer = Analyzer(dagda_server_url=dagda_server_url)

    def run_static_analysis(self, image_name=None, container_id=None):
        evaluated_docker_image = self.analyzer.evaluate_image(
            image_name=image_name, container_id=container_id)
        docker_image_name = evaluated_docker_image['image_name']
        r = requests.post(self.dagda_server_url + '/history/' +
                          docker_image_name,
                          data=json.dumps(evaluated_docker_image),
                          headers={'content-type': 'application/json'})
        # -- Print cmd output
        if r is not None and r.content:
            print(
                json.dumps(json.loads(r.content.decode('utf-8')),
                           sort_keys=True,
                           indent=4))
示例#8
0
 def initialize(self):
     if self.analyzer is not None:
         return
     self.analyzer = Analyzer(Path(self.config['model_path']), self.config['device_id'], needs_patches=True)
示例#9
0
文件: agent.py 项目: zigmax/dagda
 def __init__(self, dagda_server_url):
     super(Agent, self).__init__()
     self.dagda_server_url = dagda_server_url
     self.analyzer = Analyzer(dagda_server_url=dagda_server_url)