How to convert variable data to audio_data?
import soundcard as sc
import numpy
import speech_recognition as sr
r = sr.Recognizer()
speakers = sc.all_speakers()
mics = sc.all_microphones()
print(speakers)
print(mics)
default_mic = sc.get_microphone('2- High Definition Audio Device', include_loopback=True)
print(default_mic)
data = default_mic.record(samplerate=48000, numframes=None)
with defaultmic.recorder(samplerate=48000) as mic:
for in range(100):
data = mic.record(numframes=1024)
print(r.recognize_google(data))
Throw error
line 822, in recognize_google
assert isinstance(audio_data, AudioData), "audio_data must be audio data"
AssertionError: audio_data must be audio data
EDIT
i found the solution like this
but it takes much time to write and transcribe :'v
import soundcard as sc
import soundfile as sf
import numpy
import time
from scipy.io import wavfile
import speech_recognition as sr
recognizer = sr.Recognizer()
default_mic = sc.get_microphone('2- High Definition Audio Device', include_loopback=True)
record_object=default_mic.recorder(samplerate=44100)
How to convert variable data to audio_data? import soundcard as sc import numpy import speech_recognition as sr r = sr.Recognizer() speakers = sc.all_speakers() mics = sc.all_microphones() print(speakers) print(mics) default_mic = sc.get_microphone('2- High Definition Audio Device', include_loopback=True)
print(default_mic)
data = default_mic.record(samplerate=48000, numframes=None) with defaultmic.recorder(samplerate=48000) as mic: for in range(100): data = mic.record(numframes=1024) print(r.recognize_google(data))
Throw error line 822, in recognize_google assert isinstance(audio_data, AudioData), "
audio_data
must be audio data" AssertionError:audio_data
must be audio dataEDIT i found the solution like this but it takes much time to write and transcribe :'v
import soundcard as sc import soundfile as sf import numpy import time from scipy.io import wavfile import speech_recognition as sr
recognizer = sr.Recognizer()
default_mic = sc.get_microphone('2- High Definition Audio Device', include_loopback=True) record_object=default_mic.recorder(samplerate=44100)
print(record_object)
seconds=0.1 numframes=int(44100*seconds)
30s
max_iterations=300 expected_time_array=numpy.arange(seconds,(max_iterations+1)*seconds,seconds)
my_audio_streaming=[]
with record_object as r: start_time=time.time() for number in range(max_iterations): data=r.record(numframes) my_audio_streaming.extend(data)
sf.write('pysoundcard_recordcontinously{}.wav'.format(number), data, 44100, 'PCM_32') # add more seconds, not recommended