Translate Audio From Speaker Output In Python With Azuresdk
I'm looking to make an application, who woul'd let me translate any audio going out of the speaker in live stream. This way, i will be able to translate any videoconference from an
Solution 1:
I found a working solution. I had indeed to downsample to 16000hz and use mono channel. I base my code on this Solution, but using stream chunk rather than read from file.
My function was:
defdownsampleFrames(data, inrate=48000, outrate=16000, inchannels=2, outchannels=1):
try:
converted = audioop.ratecv(data, 2, inchannels, inrate, outrate, None)
if outchannels == 1:
converted = audioop.tomono(converted[0], 2, 1, 0)
except:
print('Failed to downsample')
returnFalsereturn converted
and from pyaudio, i send a chunk of data like this :
p = pyaudio.PyAudio()
pstream = p.open(
format=pyaudio.paInt16,
channels=2, rate=RATE,
input=True, frames_per_buffer=CHUNK,
input_device_index=5,
as_loopback=True
)
while(True):
frame = pstream.read(CHUNK)
if frame:
downFrame = downsampleFrames(frame)
stream.write(downFrame)
Post a Comment for "Translate Audio From Speaker Output In Python With Azuresdk"