分類彙整:樹莓派

【鼎革‧革鼎】︰ Raspbian Stretch 《六之 K.2-sd.IV 》

在今天用『模擬』輔助『學習』,早不是件新鮮的事。

此處略為介紹

Pyroomacoustics

Summary

Pyroomacoustics is a software package aimed at the rapid development and testing of audio array processing algorithms. The content of the package can be divided into three main components: an intuitive Python object-oriented interface to quickly construct different simulation scenarios involving multiple sound sources and microphones in 2D and 3D rooms; a fast C implementation of the image source model for general polyhedral rooms to efficiently generate room impulse responses and simulate the propagation between sources and receivers; and finally, reference implementations of popular algorithms for beamforming, direction finding, and adaptive filtering. Together, they form a package with the potential to speed up the time to market of new algorithms by significantly reducing the implementation overhead in the performance evaluation step.

Room Acoustics Simulation

Consider the following scenario.

Suppose, for example, you wanted to produce a radio crime drama, and it so happens that, according to the scriptwriter, the story line absolutely must culminate in a satanic mass that quickly degenerates into a violent shootout, all taking place right around the altar of the highly reverberant acoustic environment of Oxford’s Christ Church cathedral. To ensure that it sounds authentic, you asked the Dean of Christ Church for permission to record the final scene inside the cathedral, but somehow he fails to be convinced of the artistic merit of your production, and declines to give you permission. But recorded in a conventional studio, the scene sounds flat. So what do you do?

—Schnupp, Nelken, and King, Auditory Neuroscience, 2010

Faced with this difficult situation, pyroomacoustics can save the day by simulating the environment of the Christ Church cathedral!

At the core of the package is a room impulse response (RIR) generator based on the image source model that can handle

  • Convex and non-convex rooms
  • 2D/3D rooms

Both a pure python implementation and a C accelerator are included for maximum speed and compatibility.

The philosophy of the package is to abstract all necessary elements of an experiment using object oriented programming concept. Each of these elements is represented using a class and an experiment can be designed by combining these elements just as one would do in a real experiment.

Let’s imagine we want to simulate a delay-and-sum beamformer that uses a linear array with four microphones in a shoe box shaped room that contains only one source of sound. First, we create a room object, to which we add a microphone array object, and a sound source object. Then, the room object has methods to compute the RIR between source and receiver. The beamformer object then extends the microphone array class and has different methods to compute the weights, for example delay-and-sum weights. See the example below to get an idea of what the code looks like.

The Room class also allows one to process sound samples emitted by sources, effectively simulating the propagation of sound between sources and microphones. At the input of the microphones composing the beamformer, an STFT (short time Fourier transform) engine allows to quickly process the signals through the beamformer and evaluate the output.

Reference Implementations

In addition to its core image source model simulation, pyroomacoustics also contains a number of reference implementations of popular audio processing algorithms for

  • beamforming
  • direction of arrival (DOA) finding
  • adaptive filtering

We use an object-oriented approach to abstract the details of specific algorithms, making them easy to compare. Each algorithm can be tuned through optional parameters. We have tried to pre-set values for the tuning parameters so that a run with the default values will in general produce reasonable results.

Quick Install

Install the package with pip:

The requirements are:

 

是希望對『演算法』有興趣者,不止多個『工具箱』也。

由於樹莓派記憶體不多★蓋宜小不宜大矣☆

※ 參考 Delay Sum Beamforming

 

 

 

 

 

 

 

 

【鼎革‧革鼎】︰ Raspbian Stretch 《六之 K.2-sd.III 》

派生碼訊

丑 牛

宋‧陸游‧幽居歲暮五首‧其五

古井年年浚,荒疇日日犁。
刈茅苫鹿屋,插棘護鷄栖。
閑頼書遮眼,愁須酒到臍。
斜陽有常課,緩步上湖堤。

黑水北朱子治家有格言︰宜未雨而綢繆 ,毋臨渴而掘井。崔瑗行尚座右銘︰無使名過實,守愚聖所臧。學問一事,祇惟恐思之不精,念之不實。

派︰昔有『 Thue 』者,其言曰︰

阿克塞爾‧圖厄【挪威語 Axel Thue】一位數學家,以研究丟番圖用『有理數』逼近『實數』問題以及開拓『組合數學』之貢獻而聞名。他於一九一四發表了『詞之群論問題』Word problem for group 啟始了一個今天稱之為『字串改寫系統』SRS String Rewriting System 的先河,如從現今的研究和發現來看,它與圖靈機的『停機問題』密切相關。上個千禧年之時,John Colagioia 用『Semi-Thue System』寫了一個『奧秘的 esoteric 程式語言 Thue ,作者宣稱︰

Thue represents one of the simplest possible ways to construe 『constraint-based』基於約束 programming. It is to the constraint-based 『paradigm』典範 what languages like『 OISC 』── 單指令集電腦 One instruction set computer ── are to the imperative paradigm; in other words, it’s a 『tar pit』焦油坑.

,果然概念廣大能通天!!『 SRS 』卻是個『奧秘語言』??

生 ︰ 當真是︰ ☆★ 之火,可以燎原。能不精思實念乎?

三足鳥

180px-Processed_SAM_loki

斷頭台

人類的思維如果一旦不『審慎』,很容易邏輯『混亂』,以至於言論多所『謬誤』,有時或許『巧說詭辯』。比方說公孫龍子的『雞三足』之詭論︰…牛羊有毛,雞有羽。謂雞足一,數足二;二而一,故三。謂牛羊足一,數足四;四而一,故五。羊牛足五,雞足三,故曰:『牛合羊非雞』。非,有以非雞也。…裡頭的『謂雞足一』之『雞足』和『一』是什麼?『數足二』的『足』與『二』又是什麼?卻能相加,彷彿『一雞 + 二足』可以得到『三 \biguplus 』的一般?!已經完全不像他的『白馬非馬論』了。

洛基的賭注 Loki’s Wager
洛基乃北歐神話中以『詐騙』著名之神。傳說他曾與矮人打賭卻輸了。當矮人們依約來『提頭』時,洛基說︰沒問題』,但是必須依照『約定』,只能取走『他的頭』,而不能動著『他的脖子。於是彼此開始『爭論』該如何的『切割』:有哪些部分雙方同意『是頭』;又有哪些部分認同『是脖子只是脖子的『結束點』和頭之『開始點』究竟『是哪裡』,互相一直無法『取得共識』。於是洛基終於保住著了他的頭

── 摘自《M♪o 之學習筆記本《丑》控制︰【黑水北】當思恒念

 

當『數理』失卻了『參考系』確定『概念』之意義;宛如憑空地述說著『群論』可以將一元多次方程式可解性的問題連繫起來,豈非囫圇吞棗乎?不知滋味之物要怎樣講耶??

且思『近』之『視角大』、『遠』之『視角小』是『歐式幾何』之『性質』嗎?

300px-海岛算经

四庫全書海島算經

220px-Sea_island_survey

如果用《海島算經

三國時代魏國數學家劉徽所著的測量學著作,原為《劉徽九章算術注》第九卷勾股章內容的延續和發展,名為《九章重差圖》,附於《劉徽九章算術注》 之後作為第十章。唐代將《重差》從《九章》分離出來,單獨成書,按第一題今有望海島」,取名為《海島算經》,是《算經十書》之一。

劉徽《海島算經》「使中國測量學達到登峰造極的地步」,使「中國在數學測量學的成就,超越西方約一千年」(美國數學家弗蘭克·斯委特茲語)

之圖來作『三角測量』的計算︰

\overline{GH} = D
\overline{BG} = X
\overline{AB} = H
\angle AHB = \alpha
\angle AGB = \beta

\tan(\alpha) = \frac{H}{D + X}
\tan(\beta) = \frac{H}{X}

Sea_Island_Measurement

可以得到

H = D \cdot \tan(\alpha) \cdot \frac{1}{1 - \frac{\tan(\alpha)}{\tan(\beta)}}

然而『天很高,日很遠』,因此 \angle \beta \approx \angle \alpha ,故而很難『度量』的『精準』,一點點『角度』之『誤差』就產生了那個

失之豪釐,差以千里

的吧!!

─── 摘自《失之豪釐,差以千里!!《上》

 

難到『有限高度』 H 之物,若位在『無窮遠』 \infty 處,竟然它的『視角』 能不趨近於『零』 \to 0  嗎??

─── 《格點圖像算術《投影幾何》【一】

 

人耳只有兩隻,卻足以聽音辨位,判別聲響來處︰

Direction of arrival

In signal processing literature, direction of arrival denotes the direction from which usually a propagating wave arrives at a point, where usually a set of sensors are located. These set of sensors forms what is called a sensor array. Often there is the associated technique of beamforming which is estimating the signal from a given direction. Various engineering problems addressed in the associated literature are:

  • Find the direction relative to the array where the sound source is located
  • Direction of different sound sources around you are also located by you using a process similar to those used by the algorithms in the literature
  • Radio telescopes use these techniques to look at a certain location in the sky
  • Recently beamforming has also been used in RF applications such as wireless communication. Compared with the spatial diversity techniques, beamforming is preferred in terms of complexity. On the other hand, beamforming in general has much lower data rates. In multiple access channels (CDMA, FDMA, TDMA), beamforming is necessary and sufficient
  • Various techniques for calculating the direction of arrival, such as Angle of Arrival (AoA), Time Difference of Arrival (TDOA), Frequency Difference of Arrival (FDOA), or other similar associated techniques.

 

豈不叫人好奇!!

那麼兩耳之近,音速剛好不快,這個『三角‧時差』之法,怎能不為『初機』乎??

Implementation of an Acoustic Sensor Array on a Mobile Robotic Device for Estimating Location of a Stationary Target 

Tripp McGehee

Supervisor: Professor Arye Nehorai

Department of Electrical and Systems Engineering
Washington University in St. Louis
Spring 2007

Abstract

We implemented an acoustic sensor array on a mobile robotic device for estimating the location of a stationary target. Our goal was to build a robot that could adaptively locate and move towards a stationary sound source. We mounted an array of four omnidirectional microphones with their respective sound cards on a Lego Mindstorm. The measurements were transmitted to a computer through USB port and processed using Labview. As a first approach, we estimated the time differences of arrivals of the sound wave reaching each of the microphones for estimating the direction of the acoustic source relative to the robot. Then, the robot transmitted the command via USB to rotate towards the estimated direction of the sound. We addressed two major technical issues while implementing this project: sensor calibration and simultaneous sampling using four independent sound cards. The results of our first experiment in finding the direction of the acoustic source are encouraging. However, a more precise sampling control is required to enable implementing successfully more sophisticated algorithms, such as maximum likelihood estimation.

 

且借 ReSpeaker 4 Mic 略探『時差‧三角』法『假設』之旨也

{sound}_i \approx {sound}_j , \ if \ i \neq j

 

 

※ 註

numpy.correlate

numpy.correlate(a, v, mode=’valid’)
Cross-correlation of two 1-dimensional sequences.

This function computes the correlation as generally defined in signal processing texts:

with a and v sequences being zero-padded where necessary and conj being the conjugate.

Parameters:

a, v : array_like

Input sequences.

mode : {‘valid’, ‘same’, ‘full’}, optional

Refer to the convolve docstring. Note that the default is ‘valid’, unlike convolve, which uses ‘full’.

old_behavior : bool

old_behavior was removed in NumPy 1.10. If you need the old behavior, use multiarray.correlate.

Returns:

out : ndarray

Discrete cross-correlation of a and v.

See also

convolve
Discrete, linear convolution of two one-dimensional sequences.
multiarray.correlate
Old, no conjugate, version of correlate.

Notes

The definition of correlation above is not unique and sometimes correlation may be defined differently. Another common definition is:

which is related to c_{av}[k] by c'_{av}[k] = c_{av}[-k].

 

唯恐聲波還是跑得太快,『解析度』生疑焉??!!

故而 MIR

The autocorrelation of a signal describes the similarity of a signal against a time-shifted version of itself. For a signal x, the autocorrelation r is:

r(k) = \sum \limits_n x(n) x(n-k)

In this equation, k is often called the lag parameter. r(k) is maximized at k = 0 and is symmetric about k.

The autocorrelation is useful for finding repeated patterns in a signal. For example, at short lags, the autocorrelation can tell us something about the signal’s fundamental frequency. For longer lags, the autocorrelation may tell us something about the tempo of a musical signal.

 

筆記首重在『概念心法』,自也是『條件限定』的哩!!??

 

 

 

 

 

 

 

 

 

【鼎革‧革鼎】︰ Raspbian Stretch 《六之 K.2-sd.II 》

過去胡適先生寫了一篇《讀書》── 談讀書四到 ── 眼到口到心到手到 ── 對今天的學子來說依然十分有益。

⊙ㄚ!!『讀書』一事,怎是一個□字了得?『讀錯了書』是書不好 ,『錯讀得書』是讀不好。該如何是好?也許有個順口溜,能夠回答這個問題︰

好讀不?不好ㄏㄠˇ讀,所以讀不好。
不讀好,考不好!怕是不好ㄏㄠˋ讀。

─── 要是,需是不了不好 ─── 紅樓夢

─── 《讀錯□書⊙錯讀□書

 

若人與『錯誤』不期而遇︰

ParameterError: Input buffer must be contiguous.

 

或許指明『讀時不了』之事︰

librosa.display.waveplot

librosa.display.waveplot(y, sr=22050, max_points=50000.0, x_axis=’time’, offset=0.0, max_sr=1000, **kwargs)
Plot the amplitude envelope of a waveform.

If y is monophonic, a filled curve is drawn between [-abs(y), abs(y)].

If y is stereo, the curve is drawn between [-abs(y[1]), abs(y[0])], so that the left and right channels are drawn above and below the axis, respectively.

Long signals (duration >= max_points) are down-sampled to at most max_sr before plotting.

Parameters:

y : np.ndarray [shape=(n,) or (2,n)]

audio time series (mono or stereo)

 

恰是『補過』之時?!

Advanced I/O Use Cases

This section covers advanced use cases for input and output which go beyond the I/O functionality currently provided by librosa.

Read specific formats

librosa uses audioread for reading audio. While we chose this library for best flexibility and support of various compressed formats like MP3: some specific formats might not be supported. Especially specific WAV subformats like 24bit PCM or 32bit float might cause problems depending on your installed audioread codecs. libsndfile covers a bunch of these formats. There is a neat wrapper for libsndfile called PySoundFile which makes it easy to use the library from python.

Note

See installation instruction for PySoundFile here.

Reading audio files using PySoundFile is similmar to the method in librosa. One important difference is that the read data is of shape (nb_samples, nb_channels) compared to (nb_channels, nb_samples) in <librosa.core.load>. Also the signal is not resampled to 22050 Hz by default, hence it would need be transposed and resampled for further processing in librosa. The following example is equivalent to librosa.load(librosa.util.example_audio_file()):

 

正好『反省思辨』也!?

 

 

 

 

 

 

 

 

 

【鼎革‧革鼎】︰ Raspbian Stretch 《六之 K.2-sd.I 》

派生碼訊

子 鼠

最高樓‧杜甫

城尖徑厭施篩愁,獨立縹緲之飛樓。
峽坼雲霾龍虎臥,江清日抱黿鼉游。
扶桑西枝對斷石,弱水東影隨長流。
杖藜嘆世者誰子?泣血迸空回白頭。

︰老杜倡議拗體詩,誰知拗得拗不得?

今天小企鵝學堂上,吵吵鬧鬧,此時那些小企鵝們正憤愾的議論著禮拜天還『補課』之事的呢 !!

有的主張︰既然是天放假,幹嘛要補課。

有的辯證︰就算今天不補,改天補還不是一樣?

有的議論︰早補早了,有什麼好議論的!!

有的搞笑︰『始』安息日,『終』禮拜天!不就一天嗎??

那你可有說法?

哦!我唱ㄏㄡˇ你ㄗㄞ︰今天不只要補課,……

而且ㄍㄡˋ要實習,但是用的是『咸澤碼訊』

‧高級的

‧沒學過的

‧ㄍㄚˋ伊講不通的

唔是□派○生的呦!!

啞是甲意喝一杯咖啡??

BabyTux

graphics-tux-638974

sonictux

starbucks_tux_linux_art-555px

─── 摘自《M♪o 之學習筆記本《子》開關︰【䷝】狀態編碼

補課不易加課難,惟因學堂不好玩。

授業解惑苦失傳,道鎖高樓難復還。

讀書原是本家事,學問方田自耕耘。

─── 《神經網絡【學而堯曰】十

 

欲上最高樓者,焉能不知『登高必自卑,行遠必自邇』之理︰

禮記‧中庸

子曰:射有似乎君子,失諸正鵠,反求諸其身。君子之道,辟如行遠必自邇,辟如登高必自卑。《詩》曰:『妻子好合,如鼓瑟琴;兄弟既翕,和樂且耽。宜爾室家,樂爾妻帑。』 子曰:父母其順矣乎!

 

故而起步暫緩『語音辨識』 API 之用︰

Speech recognition module for Python, supporting several engines and APIs, online and offline. https://pypi.python.org/pypi/SpeechRe…

SpeechRecognition

Library for performing speech recognition, with support for several engines and APIs, online and offline.

Speech recognition engine/API support:

Quickstart: pip install SpeechRecognition. See the “Installing” section for more details.

To quickly try it out, run python -m speech_recognition after installing.

Project links:

Library Reference

The library reference documents every publicly accessible object in the library. This document is also included under reference/library-reference.rst.

See Notes on using PocketSphinx for information about installing languages, compiling PocketSphinx, and building language packs from online resources. This document is also included under reference/pocketsphinx.rst.

……

Requirements

To use all of the functionality of the library, you should have:

  • Python 2.6, 2.7, or 3.3+ (required)
  • PyAudio 0.2.11+ (required only if you need to use microphone input, Microphone)
  • PocketSphinx (required only if you need to use the Sphinx recognizer, recognizer_instance.recognize_sphinx)
  • Google API Client Library for Python (required only if you need to use the Google Cloud Speech API, recognizer_instance.recognize_google_cloud)
  • FLAC encoder (required only if the system is not x86-based Windows/Linux/OS X)

The following requirements are optional, but can improve or extend functionality in some situations:

  • On Python 2, and only on Python 2, some functions (like recognizer_instance.recognize_bing) will run slower if you do not have Monotonic for Python 2 installed.
  • If using CMU Sphinx, you may want to install additional language packs to support languages like International French or Mandarin Chinese.

The following sections go over the details of each requirement.

───

 

串講先補 MIR 『錄音』界面之法︰

 

 

 

 

 

 

 

 

 

 

【鼎革‧革鼎】︰ Raspbian Stretch 《六之 K.1 》

派生碼訊

巳 蛇

漫天一白漢江秋,
憔悴黃花總帶愁;
吉曜半升箕斗隱,

金烏起滅海山頭。

巳蛇︰《 文 》文說︰ 巳 巳,巳也。四月 ,陽气巳出,陰气巳藏,萬物見,成文章,故巳為蛇,象形。凡巳之屬皆从巳。

《淮南子‧天文》講︰巳則生已定也。或存巳之古意,新生兒。

蛇 蛇,它或从虫。

若講形質已具,氣息已出,因此萬物見,成文章,自然有理。但說『故 巳 巳為 蛇 蛇』從何得出?據聞蛇的古字是 它 它,當真是以『象形』形像為故,實在有點牽強。如今夏日正炎炎,何不就尋棵湯谷扶桑 ,

大樹底下好乘涼

,作此《大哉問》??

Albrecht_Dürer_-_Adam_and_Eve_(Prado)_2
夏娃的蘋果

Golden_Apple_of_Discord_by_Jacob_Jordaens
金蘋果事件

640px-Newton's_tree,_Botanic_Gardens,_Cambridge
牛頓的蘋果

青蘋果
圖靈的蘋果

根據《聖經‧創世記》記載︰

亞當和夏娃二人住在伊甸園中,後來夏娃受『』的哄誘,偷食了『知善惡樹』所結的『禁果』,也讓亞當食用,二人遂被上帝逐出伊甸園。

□︰禁果是蘋果嗎?
○︰莫宰羊!
□︰那蘋果是禁果嗎?
○︰煩惱即菩提!!

也許希臘神話中關鍵之因緣生法的一顆『金蘋果』── 獻給最美女神 ──,引發 → 帕里斯的評判,導致 → 特洛伊戰爭。明示了『蘋果』與『誘惑』的關係,至於說怎麼聯繫上了『知識』,那只能問『牛頓』的了?

雖說『牛頓』並沒有創造『機械的宇宙』,如果仔細考察『運動定律』,假使再加上『物質組構』的『構造方程式』與『初始條件』── 位置和動量 ──,那麼該物之『運動軌跡』就被『確定』了。這演示了一種『軟體設計』之方法學,它以『資料驅動』為中心。或許艾倫‧圖靈非常了解那個『抽象機械』,所以創想發明了『萬有圖靈機』。只不過人類的知識還很難駕馭那樣的『仙女計算機』,然而隨著一九六零年代以來『硬體描述語言』 HDL hardware description language 的發展,也許我們終將受邀進入『計算機械的世界 』,一探『軟硬體的真諦』!『圖靈的蘋果』正述說著『尊重』與『寬容』,如今想來他早已『知道』這些『演算法』了的吧!!

……

訊 ︰☿ 《風俗通》裡記載:杜宣夏至日赴飲,見酒杯中似有蛇 ,然不敢不飲。酒後胸腹痛切,多方醫治不愈。後得知壁上赤弩照于杯中,影如蛇,病即愈。

, 未雨先綢繆!又豈是杯弓蛇影胡疑猜?寧夜靜思,

夏至日作》權德輿

睿樞無停運,
四序相錯行。
寄言赫曦景,
今日一陰生。

忽兒,一日又將盡!!

─── 《【䷁】黃裳元吉

 

若是祇談播、錄之事

Play and Record Sound with Python

This Python module provides bindings for the PortAudio library and a few convenience functions to play and record NumPy arrays containing audio signals.

Documentation:
http://python-sounddevice.readthedocs.io/
Source code repository and issue tracker:
https://github.com/spatialaudio/python-sounddevice/
License:
MIT — see the file LICENSE for details.

實想消弭警告不輸出

 

自己寫程式之人!果無選擇的乎?