首页 > 解决方案 > 在 GNURadio/GRC 中,如何顺序使用不同的音频源作为输入,而无需手动启动和停止?

问题描述

我的流程图中有 3-4 个不同的音频源。我想背靠背播放每个源(而不是相互重叠),而不必手动启动和停止每个源。本质上,就像一个计时器。例如,播放源 1 然后停止,等待 15 秒,播放源 2,等待 30 秒,依此类推......流程图中是否有可以执行此操作的块,或者是否有人有执行此操作的 python 块已经或类似的东西?

标签: pythongnuradiognuradio-companion

解决方案


以我自己的方式想出来......基本上我制作了自己的嵌入式python块,它将我想要的输入延迟了这么多秒。这是我想出的:

import time 
import numpy as np
from gnuradio import gr


class blk(gr.sync_block):  
    """Embedded Python Block that time delays the input file"""

    # initializes the GRC Block input, output, block title, and parameters
    def __init__(self, delay = 0):  
        gr.sync_block.__init__(
            self,
            name='Time Delayed Input',
            in_sig=[np.float32],
            out_sig=[np.float32]
        )
 
        # sets a callback for time delay in seconds specified in the GRC block
        self.delay = time.sleep(delay)

    def work(self,  input_items,  output_items):
        
        # sets output equal to the input to just pass through the block 
        output_items[0][:] = input_items[0]
        
        # calls a time delay in seconds 
        sleep.delay

        # returns the input as the output after the specified delay 
        return len(output_items[0])

推荐阅读