Py conjp2019 renyuanlyu_3

Renyuan Lyu
Renyuan LyuAssociate Professor at Chang Gung Univ
Real-time Pitch Detection
and Speech Recognition
in Python
via Pyaudio, Pygame & Vpython
Renyuan Lyu (呂仁園),
Chang Gung University (長庚大學),
TAIWAN (台灣)
@ Pycon JP 2019 1
class SelfIntroduction自己紹介:
2
def __init__ (私):
私.名 = 'Renyuan Lyu, 呂 仁園'
私.職業 = 'University Teacher, 大学の先生'
私.研究分野 = 'Speech Recognition, 音声認識'
私.職場 = 'Chang Gung Univ (CGU), 長庚大學'
私.国 = 'TAIWAN, 台灣’
3
def introduce (私):
私.誇り = ‘’’ Becoming an associate prof
20+ years ago.’’’
私.恥ずかしさ = ‘’’Still being the associate prof
after those 20+ years ’’’
私.挑戦= “Marathon runner/walker, 2019”
私.興味= '‘’ Being the Pycon JP speaker
(2015~2017, 2019 ), カラオケさん’‘’
田沢湖マラソン、2019/09/15
4535人が力走
4
https://www.sakigake.jp/news/article/20190915AK0028/
https://youtu.be/O1-9Yv9cB8Q
5
https://youtu.be/cUewj2kRrbk?t=2434
Lightning Talks at PyCon JP 2016, 2017
Real-time Pitch Detection
and Speech Recognition
in Python
via Pyaudio, Pygame & Vpython
6
The System
Overview
7
Multilingual
Lyric Transcription
(Speech Recognition)
Pitch
Detection
(Melody Recognition)
https://youtu.be/XF3oGwEsPac
The System
Blockdiagram
Singing
Voice
Multilingual
Lyric Transcription
(Speech Recognition)
Pitch
Detection
(Melody Recognition)
Lyrics (歌詞)
“Twinkle Twinkle Little Star”
“きらきらひかる”
“一閃一閃亮晶晶”
Pitch (musical notes, 音符)
“C C G G A A C –”
8
Audio Data (Voice) Acquisition
• Audio Signal Processing
• samplingRate= 16000 samples/sec,
• bitsPerSample= 16 bits/sample = 2 bytes/sample
• channelNumber= 3 (L, R, humming)
• Frame-wise short-time processing
Frame01
Frame02
9
Digital Signal Processing:
Spectrogram
• A spectrogram is
• a visual representation
• of the spectrum
• of frequencies
• of a signal
• as it varies with time.
• using Fast Fourier Transform
• FFT
10
https://youtu.be/bCRL5yw8fXA
A Real-time Spectrogram
http://friture.org/
11
https://youtu.be/1sbtXqZaGXE
• Friture is a program in PYTHON
designed to analyze audio input in
real-time.
• It displays audio data as a scope, a
spectrum analyzer, or with a rolling
2D spectrogram.
• I found this program in 2012~2013
and was totally convinced that I can
transfer into the PYTHON world to
continue my career.
Using Audacity
to get audio signal
12
https://youtu.be/o9DF9SVdcVo
The first step to do audio signal processing
is to get some audio signal by yourself
and play with it.
Sound file
PCM format
(.wav)
• http://soundfile.sapp.org
/doc/WaveFormat/
13
• Compared with text data,
audio data is much bigger,
and it is usually stored in
binary form.
• Being familiar with the data
format is crucial to process it.
“See” the audio signal in the raw format
14
Extract audio header information
15
Visualize the audio signal in waveform
• As long as you can visualize the
audio signal, you can make sure
you read them in a correct way,
• and then you can do further
processing via advanced signal
processing algorithms
• like Pitch Detection and Speech
Recognition.
16
Human aided pitch tracking
by Humming
• Pitch Detection for real music
signal is not easy by itself.
• To simplify the task, I use
some TRICK….
• I hum the song and record it in
another channel, while listening
the music.
• I use this “clean” humming
voice to detect the pitch.
17
Multi-Threading Programming
18
def init(self):
self.錄音線= threading.Thread(target= self.錄音線程)
self.能量線= threading.Thread(target= self.f1_能量)
self.基頻線= threading.Thread(target= self.f4_基頻)
self.語音辨認線= threading.Thread(target= self.f6_語音辨認)
def start(self):
self.錄音線.start()
self.能量線.start()
self.基頻線.start()
self.語音辨認線.start()
• For a Realtime system,
the multi-threading
programming is crucial,
• At least, an independent
thread for data
acquisition is necessary.
audio recording “Thread”
19
A circular buffer
to store the real-time
audio signal
20
I set a buffer in RAM to store 16 sec of voice,
It is of size 16*16000*2*3= 1,536,000 bytes
Pitch Detection Algorithm
21
• Zoom a speech signal into scale of .01 sec, We
can visualize there are periodic patterns.
• the duration of a periodic pattern is called
the “pitch period”.
• For the A-440 note, the pitch period =
1/440 = .0023 sec
• A traditionally popular pitch detection
algorithm is based on auto-correlation
method.
Pitch Detection Thread
22
Pitch Sampling at slower intervals
23
Pitch Quantization
24
Speech Recognition
• http://shorturl.at/rxLM4
25
26
Speech Recognition
need Large-scale of Database
to train the system.
Nowadays, Deep-learning
algorithms play the major roles
and achieve the greatest
performance.
Speech Recognition in Python
27
https://pypi.org/project/SpeechRecognition/
Google has a great Speech Recognition API.
This API converts speech ( from microphone)
into written text (as Python strings)
the ASR Thread
28
Get a segment (M frames) of speech ➔ x
Transform x into an “AudioData” and then
send it to Google Speech Recognition engine
to get a recognition output “text”.
To get speech data from a circular buffer is
quite an issue for implementation. !!
29
def 語音辨認(私):
辨= sr.Recognizer()
while self.語音辨認中==True:
#
# Get x as "singingVoice" to be 音
#
音= sr.AudioData(x, 私.取樣率, 私.樣本寬)
#
# Do ASR to get recognition Result as 文
#
try:
if lang=='ja':
文= 辨.recognize_google(音, language='ja')
elif lang=='en':
文= 辨.recognize_google(音, language='en')
elif lang= 'zh-TW'
文= 辨.recognize_google(音, language='zh-TW')
else:
私.文= '{} ({})'.format(文, lang)
except:
私.文= 'exceptionOccurs!!'
pass
return
Lyric Transcription
• Melodic voice (singing) recognition
• Timed Text Generation
• Need do Speech recognition and
segmentation
• Currently, it was done by human,
not yet by machine.
30
Kara OK
• Pitch Tracking
• Timed Text Displaying
31
https://youtu.be/F1_Xz1c5AEE
Final Demo
32
https://youtu.be/0cdo6ZnBZc8
ご清聴ありがとうございました。
Thank you for listening.
感謝聆聽。
@ PyCon Jp 2019
Renyuan Lyu (呂仁園)
from TAIWAN (台灣)
33
1 of 33

Recommended

Py conjp2019 renyuanlyu_3 by
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Renyuan Lyu
87 views30 slides
Py conjp2019 renyuanlyu_3 by
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Renyuan Lyu
69 views30 slides
Pycon apac 2014 by
Pycon apac 2014Pycon apac 2014
Pycon apac 2014Renyuan Lyu
4.3K views42 slides
Digital signal processing through speech, hearing, and Python by
Digital signal processing through speech, hearing, and PythonDigital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonMel Chua
24.4K views76 slides
pyconjp2015_talk_Translation of Python Program__ by
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__Renyuan Lyu
4.2K views44 slides
Python Workshop by
Python WorkshopPython Workshop
Python WorkshopMantavya Gajjar
1.1K views48 slides

More Related Content

What's hot

Python and Machine Learning by
Python and Machine LearningPython and Machine Learning
Python and Machine Learningtrygub
9.8K views58 slides
Fun with MATLAB by
Fun with MATLABFun with MATLAB
Fun with MATLABritece
2.9K views31 slides
Introduction of ToySynth by
Introduction of ToySynthIntroduction of ToySynth
Introduction of ToySynthRansui Iso
1.9K views15 slides
Introduction to Python Pandas for Data Analytics by
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
1.7K views115 slides
Digital speech processing lecture1 by
Digital speech processing lecture1Digital speech processing lecture1
Digital speech processing lecture1Samiul Parag
12.1K views20 slides
Python basics by
Python basicsPython basics
Python basicsJyoti shukla
470 views37 slides

What's hot(19)

Python and Machine Learning by trygub
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
trygub9.8K views
Fun with MATLAB by ritece
Fun with MATLABFun with MATLAB
Fun with MATLAB
ritece2.9K views
Introduction of ToySynth by Ransui Iso
Introduction of ToySynthIntroduction of ToySynth
Introduction of ToySynth
Ransui Iso1.9K views
Introduction to Python Pandas for Data Analytics by Phoenix
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
Phoenix 1.7K views
Digital speech processing lecture1 by Samiul Parag
Digital speech processing lecture1Digital speech processing lecture1
Digital speech processing lecture1
Samiul Parag12.1K views
(2014-05-24) [Taubaté Perl Mongers] AudioLazy Python DSP (Digital Signal Proc... by Danilo J. S. Bellini
(2014-05-24) [Taubaté Perl Mongers] AudioLazy Python DSP (Digital Signal Proc...(2014-05-24) [Taubaté Perl Mongers] AudioLazy Python DSP (Digital Signal Proc...
(2014-05-24) [Taubaté Perl Mongers] AudioLazy Python DSP (Digital Signal Proc...
Python programming | Fundamentals of Python programming by KrishnaMildain
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
KrishnaMildain882 views
Statistics Using Python | Statistics Python Tutorial | Python Certification T... by Edureka!
Statistics Using Python | Statistics Python Tutorial | Python Certification T...Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Edureka!944 views
Multimedia by BUDNET
MultimediaMultimedia
Multimedia
BUDNET751 views
Conditional generative model for audio by Keunwoo Choi
Conditional generative model for audioConditional generative model for audio
Conditional generative model for audio
Keunwoo Choi183 views
Python interview questions for experience by MYTHILIKRISHNAN4
Python interview questions for experiencePython interview questions for experience
Python interview questions for experience
MYTHILIKRISHNAN443 views
Mp smeeting 09_20_12 by mabashin
Mp smeeting 09_20_12Mp smeeting 09_20_12
Mp smeeting 09_20_12
mabashin170 views
Writing Fast Code (JP) - PyCon JP 2015 by Younggun Kim
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
Younggun Kim1.7K views
How speech reorganization works by Muhammad Taqi
How speech reorganization worksHow speech reorganization works
How speech reorganization works
Muhammad Taqi779 views

Similar to Py conjp2019 renyuanlyu_3

Pod Series Audio14 by
Pod Series Audio14Pod Series Audio14
Pod Series Audio14Dan Cabrera
280 views60 slides
Pod Series Audio10 by
Pod Series Audio10Pod Series Audio10
Pod Series Audio10Dan Cabrera
433 views57 slides
Desktop assistant by
Desktop assistant Desktop assistant
Desktop assistant PRASUNCHAKRABORTY21
1.9K views23 slides
Podcasting in Education by
Podcasting in EducationPodcasting in Education
Podcasting in EducationBenjamin Kreeger
869 views60 slides
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang... by
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Edureka!
2.3K views62 slides
Podcasting by
PodcastingPodcasting
PodcastingCraig Lawson
785 views18 slides

Similar to Py conjp2019 renyuanlyu_3(20)

Pod Series Audio14 by Dan Cabrera
Pod Series Audio14Pod Series Audio14
Pod Series Audio14
Dan Cabrera280 views
Pod Series Audio10 by Dan Cabrera
Pod Series Audio10Pod Series Audio10
Pod Series Audio10
Dan Cabrera433 views
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang... by Edureka!
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Edureka!2.3K views
Pythonlearn-01-Intro.pptx by MrHackerxD
Pythonlearn-01-Intro.pptxPythonlearn-01-Intro.pptx
Pythonlearn-01-Intro.pptx
MrHackerxD13 views
Py4 inf 01-intro by Ishaq Ali
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
Ishaq Ali378 views
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ... by Edureka!
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Edureka!3.2K views
Automatic subtitle generation by tanyasaxena1611
Automatic subtitle generationAutomatic subtitle generation
Automatic subtitle generation
tanyasaxena16117.3K views

More from Renyuan Lyu

Lightning talk01 docx by
Lightning talk01 docxLightning talk01 docx
Lightning talk01 docxRenyuan Lyu
80 views2 slides
Lightning talk01 by
Lightning talk01Lightning talk01
Lightning talk01Renyuan Lyu
155 views5 slides
Pycon JP 2016 ---- Pitch Detection by
Pycon JP 2016 ---- Pitch DetectionPycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch DetectionRenyuan Lyu
136 views1 slide
pycon jp 2016 ---- CguTranslate by
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslateRenyuan Lyu
58 views1 slide
Ry pyconjp2015 turtle by
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtleRenyuan Lyu
589 views40 slides
教青少年寫程式 by
教青少年寫程式教青少年寫程式
教青少年寫程式Renyuan Lyu
1.5K views32 slides

More from Renyuan Lyu(6)

Lightning talk01 docx by Renyuan Lyu
Lightning talk01 docxLightning talk01 docx
Lightning talk01 docx
Renyuan Lyu80 views
Lightning talk01 by Renyuan Lyu
Lightning talk01Lightning talk01
Lightning talk01
Renyuan Lyu155 views
Pycon JP 2016 ---- Pitch Detection by Renyuan Lyu
Pycon JP 2016 ---- Pitch DetectionPycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch Detection
Renyuan Lyu136 views
pycon jp 2016 ---- CguTranslate by Renyuan Lyu
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslate
Renyuan Lyu58 views
Ry pyconjp2015 turtle by Renyuan Lyu
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
Renyuan Lyu589 views
教青少年寫程式 by Renyuan Lyu
教青少年寫程式教青少年寫程式
教青少年寫程式
Renyuan Lyu1.5K views

Recently uploaded

802.11 Computer Networks by
802.11 Computer Networks802.11 Computer Networks
802.11 Computer NetworksTusharChoudhary72015
9 views33 slides
Quality Manual Chaity Group.pdf by
Quality Manual Chaity Group.pdfQuality Manual Chaity Group.pdf
Quality Manual Chaity Group.pdfMizan Rahman
5 views61 slides
START Newsletter 3 by
START Newsletter 3START Newsletter 3
START Newsletter 3Start Project
5 views25 slides
Machine learning in drug supply chain management during disease outbreaks: a ... by
Machine learning in drug supply chain management during disease outbreaks: a ...Machine learning in drug supply chain management during disease outbreaks: a ...
Machine learning in drug supply chain management during disease outbreaks: a ...IJECEIAES
12 views17 slides
Control Systems Feedback.pdf by
Control Systems Feedback.pdfControl Systems Feedback.pdf
Control Systems Feedback.pdfLGGaming5
5 views39 slides
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Tsuyoshi Horigome
23 views16 slides

Recently uploaded(20)

Quality Manual Chaity Group.pdf by Mizan Rahman
Quality Manual Chaity Group.pdfQuality Manual Chaity Group.pdf
Quality Manual Chaity Group.pdf
Mizan Rahman5 views
Machine learning in drug supply chain management during disease outbreaks: a ... by IJECEIAES
Machine learning in drug supply chain management during disease outbreaks: a ...Machine learning in drug supply chain management during disease outbreaks: a ...
Machine learning in drug supply chain management during disease outbreaks: a ...
IJECEIAES12 views
Control Systems Feedback.pdf by LGGaming5
Control Systems Feedback.pdfControl Systems Feedback.pdf
Control Systems Feedback.pdf
LGGaming55 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa... by ijseajournal
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
ijseajournal5 views
A multi-microcontroller-based hardware for deploying Tiny machine learning mo... by IJECEIAES
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
IJECEIAES13 views
fakenews_DBDA_Mar23.pptx by deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra814 views
Advances in micro milling: From tool fabrication to process outcomes by Shivendra Nandan
Advances in micro milling: From tool fabrication to process outcomesAdvances in micro milling: From tool fabrication to process outcomes
Advances in micro milling: From tool fabrication to process outcomes
Machine Element II Course outline.pdf by odatadese1
Machine Element II Course outline.pdfMachine Element II Course outline.pdf
Machine Element II Course outline.pdf
odatadese18 views
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L... by Anowar Hossain
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
Anowar Hossain12 views
MSA Website Slideshow (16).pdf by msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla64 views

Py conjp2019 renyuanlyu_3