0

I'm working on a project where I'm streaming live audio from an old Android phone to a server (Ubuntu) for python speech recognition. I can listen to the live audio stream with VLC fine but can't figure out how to get it into Python.

I'm using this speech recognition module (https://github.com/Uberi/speech_recognition) which relies on PyAudio for microphone input. What's the best way to get my live network audio into this module?

Is a virtual microphone on the server linked to the network stream the best (and how would I go about this?) or can Python just listen to the stream directly?

I attempted this code but it didn't work, saying AssertionError: Source must be an audio source

import requests
stream_url = "http://username:password@IPAddress:port/audio.wav"
n = requests.get(stream_url, stream=True)

r = sr.Recognizer()
mic = sr.Microphone()
with n as source:
    audio = r.listen(source)
try:
    print(r.recognize_google(audio))
except UnknownValueError:
    print("Couldn't Recognize")

If someone could point me in the right direction that would be awesome. Thanks!

James Watson
  • 35
  • 1
  • 4
  • Can you get the straight mic example to work? https://github.com/Uberi/speech_recognition/blob/master/examples/microphone_recognition.py – fdcpp Jan 23 '22 at 07:36
  • Yes I've got real time transcription working with a mic plugged in but this won't work for my project, need to use the audio stream over my network – James Watson Jan 23 '22 at 09:01
  • I’d try to approach this by getting Pyaudio to read a stream over the network directly. https://gist.github.com/fopina/3cefaed1b2d2d79984ad7894aef39a68 After _that_ then I’d look into wrapping that operation so that it conforms to https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst#recognizer_instancelistensource-audiosource-timeout-unionfloat-none--none-phrase_time_limit-unionfloat-none--none-snowboy_configuration-uniontuplestr-iterablestr-none--none---audiodata – fdcpp Jan 23 '22 at 10:21
  • Ok thank you! I'll give it a shot – James Watson Jan 23 '22 at 18:16

0 Answers0