!pip install speechrecognition pydub
!pip3 install sounddevice
!pip3 install wavio
!pip install scipy
Speech recognition
Converting audio speech to text
Resources / Sources
Installs
Create a recording
# import required libraries
import sounddevice as sd
from scipy.io.wavfile import write
import wavio as wv
# Sampling frequency
= 44100
freq
# Recording duration
= 20
duration
# Start recorder with the given values
# of duration and sample frequency
= sd.rec(int(duration * freq),
recording =freq, channels=2)
samplerate
# Record audio for the given number of seconds
sd.wait()
# This will convert the NumPy array to an audio
# file with the given sampling frequency
# write("recording0.wav", freq, recording)
# Convert the NumPy array to audio file
="recording1.wav"
fileo=2) wv.write(fileo, recording, freq, sampwidth
To make it an arbitrary duration
https://python-sounddevice.readthedocs.io/en/0.3.12/examples.html#recording-with-arbitrary-duration
Convert Audio to text
import speech_recognition as sr
= fileo
AUDIO_FILE = sr.Recognizer()
r with sr.AudioFile(AUDIO_FILE) as source:
= r.record(source) # read the entire audio file
audio
try:
# we're just using the default API key
print("->> " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
->> I heard you have a compilation of every good song ever done by anybody every great song by The Beach Boys All the underground hits all the modern lovers tracks I heard you have a vinyl record on German imports I heard that you have a white label every cm
When reading out Losing My Edge by LCD Soundsystem
I heard you have a compilation of every good song ever done by anybody. Every great song by the Beach Boys. All the underground hits. All the Modern Lovers tracks. I heard you have a vinyl of every Niagra record on German import. I heard that you have a white label of every semina