Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0a5 - read_audio reads old voices #257

Open
onurgule opened this issue Apr 28, 2024 · 0 comments
Open

2.0.0a5 - read_audio reads old voices #257

onurgule opened this issue Apr 28, 2024 · 0 comments

Comments

@onurgule
Copy link

onurgule commented Apr 28, 2024

Hello,

I am using read_audio function to do something then I respond with write_audio.

   while pcall.state == call.CallState.ANSWERED:
        if silence_counter >= max_silence_count:
            break
        data = pcall.read_audio(length=800, blocking=True)
        if data and ((data.count(b"\x80") + data.count(b"\x7f")) / len(data)) <= 0.94:
            w.writeframes(data)
        
        time.sleep(1 / (8000 / 800))

After then, I respond with write_audio due to command:

    f = wave.open(file, 'rb')

    frames = f.getnframes()
    data = f.readframes(frames)
    f.close()
    print("FRAMES:",frames)

    pcall.write_audio(data)  # This writes the audio data to the transmit buffer
    print("Data are in buffer and playing")

    stop = time.time() + (frames / 8000)  # frames/8000 is the length of the audio in seconds

    while time.time() <= stop and pcall.state == call.CallState.ANSWERED:
        time.sleep(0.1)
    print("Message finished")

But, when I interrupt and speak while write_audio running, it detects after writing finished and reading starts.
For example:

Script: Hello, how can I help you?
Me: Turn on the lights.
Script: Alright, I am turning... (I INTERRUPT IT and say "No, Close the lights") ... the lights. Anything else?
Me: Thank you.
Script: (It reads audio like "No, Close the lights thank you"): Okay, I am closing the lights.

I used 1.6.7 and 2.0.0a5 and both versions didn't work.
I want to read audio only when I want to read, not previous voices.

Also, I tried blocking=False but it didn't work and also has many delay because of writing.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant