Ejemplo n.º 1
0
    def __init__(self, parent, path):
        super().__init__()
        self.parent = parent
        # self.scroll = QScrollArea(self)
        self.fig, self.ax = plt.subplots(1)
        DPI = self.fig.get_dpi()
        # self.fig.set_size_inches(7200.0/float(DPI),190.0/float(DPI))
        self.figure_canvas = FigureCanvas(self.fig)
        self.figure_canvas.setParent(self)
        # self.scroll.setWidget(self.figure_canvas)
        # self.scroll.setFixedHeight(200)
        # self.scroll.setFixedWidth(750)
        layout = QVBoxLayout(self)
        layout.addWidget(self.figure_canvas)
        # self.setFixedWidth(750)
        self.setFixedHeight(300)
        sound = AudioSegment.from_file(get_path(path), "mp3")
        data = np.array(sound.get_array_of_samples())
        data = data[::sound.channels]
        self.data = data[::int(sound.frame_rate / 100)]
        self.offset = 0
        self.ax.plot(range(self.offset, self.offset + 2000),
                     self.data[self.offset:self.offset + 2000])
        self.ax.get_yaxis().set_visible(False)
        self.start = None
        self.end = None
        self.fill = None
        self.fig.canvas.mpl_connect('scroll_event', self.on_scroll)
        self.fig.canvas.mpl_connect('button_press_event', self.on_press)
        self.fig.canvas.mpl_connect('button_release_event', self.on_release)

        self.player = Player(path)
Ejemplo n.º 2
0
 def __init__(self, path):
     super().__init__()
     if path:
         sound = QMediaContent(QUrl.fromLocalFile(get_path(path)))
         self.setMedia(sound)
     else:
         play_list = QMediaPlaylist()
         play_list.setPlaybackMode(QMediaPlaylist.Sequential)
         self.setPlaylist(play_list)
         self.play_list = play_list
Ejemplo n.º 3
0
    def play(self, start=None, end=None, files=None):
        if files:
            self.play_list.clear()
            for file in files:
                self.play_list.addMedia(
                    QMediaContent(QUrl.fromLocalFile(get_path(file))))
            super().play()
        else:
            self.setPosition(start)
            super().play()

            while self.position() <= end:
                continue
            self.stop()
Ejemplo n.º 4
0
def write_file(path, data):
    with open(get_path(path), 'w') as f:
        json.dump(data, f, indent=2, ensure_ascii=False)
Ejemplo n.º 5
0
def read_file(path):
    with open(get_path(path)) as f:
        data = json.load(f)
    return data
Ejemplo n.º 6
0
 def save(self):
     # print(self.file)
     with open(get_path(self.file), 'w') as f:
         json.dump(self.article, f, indent=2, ensure_ascii=False)