【发布时间】:2019-12-27 18:50:13
【问题描述】:
我想从网站上抓取多个音频通道。我想同时实时执行以下操作:
1. Save the audio to GCP Storage.
2. Apply speech-to-text ML and send transcripts to an app.
我想重点关注这篇文章的 (1)。在 GCP 中执行此操作的最佳方法是什么,是 Pubsub 吗?如果不是,那么构建它的最佳方法是什么?
我有一个功能性 Python 脚本。
设置录音功能。
def record(url):
# Open url.
response = urllib.request.urlopen(url)
block_size = 1024
# Make folder with station name.
# Example, 'www.music.com/station_1' has folder name of '/station_1/'
channel = re.search('([^\/]+$)' , url)[0]
folder = '/' + channel + '/'
os.makedirs(os.path.dirname(folder), exist_ok=True)
# Run indefinitely
while True:
# Name recording as the current date_time.
filename = folder + time.strftime("%m-%d-%Y--%H-%M-%S") + '.mp3'
f = open(filename, 'wb')
start = time.time()
# Create new file every 60 seconds.
while time.time() - start < 60:
buffer = response.read(block_size)
f.write(buffer)
f.close()
声明要记录的 URL
urls = ['www.music.com/station_1',...,'www.music.com/station_n']
线程一次从多个 URL 记录。
p = Pool(len(urls))
p.map(record, urls)
p.terminate()
p.join()
【问题讨论】:
标签: google-cloud-platform google-cloud-storage google-cloud-dataflow apache-beam google-cloud-pubsub