Giter Club home page Giter Club logo

Comments (3)

KoljaB avatar KoljaB commented on August 13, 2024

No, just leave it as it is. The feed_audio method takes care of the buffer size.

You just need to ensure that the input chunks are PCM raw data and 16000 Hz sample rate:

from scipy.signal import resample

def decode_and_resample(
		audio_data,
		original_sample_rate,
		target_sample_rate):

	# Decode 16-bit PCM data to numpy array
	audio_np = np.frombuffer(audio_data, dtype=np.int16)

	# Calculate the number of samples after resampling
	num_original_samples = len(audio_np)
	num_target_samples = int(num_original_samples * target_sample_rate /
							 original_sample_rate)

	# Resample the audio
	resampled_audio = resample(audio_np, num_target_samples)

	return resampled_audio.astype(np.int16).tobytes()

resampled_chunk = decode_and_resample(chunk, sample_rate, 16000)
recorder.feed_audio(resampled_chunk)

from realtimestt.

jacobtang avatar jacobtang commented on August 13, 2024

Thanks! Can feed_audio with 16k stereo data?the raw data is 48k,stereo data,when i call decode_and_resample,the audio data is 16k stereo.
In my realtime server,I can not get recorder.text() in a loop by using thread,may be the feed data is not correct.

from realtimestt.

KoljaB avatar KoljaB commented on August 13, 2024

Should be mono 16000 Hz, 16 Bit, PCM

from realtimestt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.