1. 录音小工具

GitHub用户:wkyo 提交的PR 录音小工具代码规范化与重命名

相关介绍

对录音小工具的代码进行了规范化,抽离出录音部分作为单独函数存在,并将实际录音操作放置到__main__中,支持手动设置录音参数。

usage: speech_recorder.py [-h] [-d DURATION] [-r SAMPLING_RATE]
                          [-b {8,16,24,32}] [-c CHANNELS]
                          [output]

Simple Wave Audio Recorder

positional arguments:
  output                audio file to store audio stream (default: output.wav)

optional arguments:
  -h, --help            show this help message and exit
  -d DURATION, --duration DURATION
                        maximum duration in seconds (default: 10)
  -r SAMPLING_RATE, --sampling-rate SAMPLING_RATE
                        sampling rate (default: 16000)
  -b {8,16,24,32}, --sampling-bits {8,16,24,32}
                        sampling bits (default: 16)
  -c CHANNELS, --channels CHANNELS
                        audio channels (default: 1)

修改后的录音工具与原始工具兼容,默认最大录音时长10s,支持在录音过程中通过Ctrl-C提前结束录音。

使用样例:

$ python speech_recorder.py -b 32 -d 5
ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Start to record with 5-seconds audio
Type Ctrl-C to get an early stop (a shorter audio)
................................................^C
-*- Early stop with 3 seconds

Recording finished
Convert PCM frames to WAV... OK

2. gRPC协议生成代码工具

$ cd assets/
$ python -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=. ./asrt.proto
作者:AI柠檬  创建时间:2021-11-26 17:58
 更新时间:2024-11-06 22:17