How to stream audio to speech api while recording ?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 353
- PR merge metrics
- No merged PRs in 30d
Description
Hello guys, I'm trying to reduce the latency time in my project, so I have been
trying to send chunks of an audio while I record it, what I had tried until now was mix a code that sends a previously recorded audio by chunks:
def RecognizeSpeech(AUDIO_FILENAME,CHUNK_SIZE):
client = Wit('MYTOKENHERE')
def wavIterator():
wav = open(AUDIO_FILENAME, 'rb')
chunk = wav.read(CHUNK_SIZE)
while chunk:
yield chunk
chunk = wav.read(CHUNK_SIZE)
resp = client.speech(wavIterator(), None,
{'Content-Type': 'audio/wav', 'Transfer-encoding':'chunked'})
with this tutorial's code: https://indianpythonista.wordpress.com/2017/04/10/speech-recognition-using-wit-ai/
and made this frankstein:
def recReturnWavIterator(RECORD_SECONDS, CHUNK_SIZE, client):
#--------- SETTING PARAMS FOR OUR AUDIO FILE ------------#
FORMAT = pyaudio.paInt16 # format of wave
CHANNELS = 2 # no. of audio channels
RATE = 44100 # frame rate
CHUNK = CHUNK_SIZE # frames per audio sample
#--------------------------------------------------------#
# creating PyAudio object
audio = pyaudio.PyAudio()
# open a new stream for microphone
# It creates a PortAudio Stream Wrapper class object
stream = audio.open(format=FORMAT,channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print("Listening")
for i in range(int(RATE / CHUNK * RECORD_SECONDS)-1):
# read audio stream from microphone
data = stream.read(CHUNK)
yield data
print("Finished recording")
def RecognizeSpeech(CHUNK_SIZE):
client = Wit('MYTOKENHERE')
resp = client.speech(recReturnWavIterator(5,CHUNK_SIZE,client),None,{'Content-Type': 'audio/wav', 'Transfer-encoding': 'chunked'})
print('Yay, got Wit.ai response: ' + str(resp))
wich does return always an empty text
Yay, got Wit.ai response: {'_text': None, 'entities': {}, 'msg_id': '7ed74ba3-698a-41a9-8158-8dd3857c3808'}
Is it possible to do something like that ? How ?
PS: Sorry, I am not very experienced with programming.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the issue's RecognizeSpeech and recReturnWavIterator functions, then inspect the pywit client.speech entry point and its audio request expectations. Establish whether microphone chunks can be streamed in this form and define completion by obtaining a non-empty transcript or documenting the supported limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100