Pyaudio与plotly和Dash-python在绘制实时音频时面临的问题

2024-10-02 04:23:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用pyaudio的实时音频信号来用plotly在破折号上绘图和处理,但是当我在updategraph scatter中传递数据块时,它只返回整数而不是音频信号块,我试了很多次,但不知道如何传递该函数并通过回调函数来更新它。 在updategraphscatter函数中,如果我不返回任何值,那么我可以在函数中打印chunk值,但是当我绑定到返回它时,它会变为int值。你知道吗

@app.callback(Output('live-graph', 'figure'),
        [Input('graph-update', 'n_intervals')])

def update_graph_scatter(mic1):
    print("Mic1 here :", mic1)
    for chunk in mic1.read_chunks():
        ch1 = chunk[0::6]
        Data=ch1/2048
        #frequencies, times, spectrogram = signal.spectrogram(Data, 16000)
        print("Data :", type(Data))
        Y.append(Data)
        print("Y Now : ", list(Y[0]))
        temp = np.arange(20)
        var = temp + 20
        X.append(var)
        #print("X here : ", X)

        data = plotly.graph_objs.Scatter(
                x=list(X),
                y=list(Y[0]),
                name='Scatter',
                mode= 'lines+markers'
                )

        return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X[0]), max(X[0])]), yaxis=dict(range=[min(Y[0]), max(Y[0])]), plot_bgcolor = app_colors['background'], paper_bgcolor = app_colors['background'])}

在updategraphscatter函数中,如果我不返回任何值,那么我可以在函数中打印chunk值,但是当我绑定到返回它时,它会变为int值。你知道吗


Tags: 函数appdata信号plotly音频listgraph

热门问题