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

Example audio only client was only sending or receiving not both. #98

Open
l33tlinuxh4x0r opened this issue Feb 4, 2021 · 3 comments
Open

Comments

@l33tlinuxh4x0r
Copy link

l33tlinuxh4x0r commented Feb 4, 2021

I downloaded the audio only client and had to change some of the imports to get it to work as well as separate the audio listeners to get it to work. Here is the updated script if anyone wants it. I'm on linux by the way... This might fix the issues with the RPi 3B+?

# A python script to do both listening and talking. This is the basic model
# for an audio-only mumble client.

# Usage:

# Install pyaudio (instructions: https://people.csail.mit.edu/hubert/pyaudio/#downloads)
# If `fatal error: 'portaudio.h' file not found` is encountered while installing
# pyaudio even after following the instruction, this solution might be of help:
# https://stackoverflow.com/questions/33513522/when-installing-pyaudio-pip-cannot-find-portaudio-h-in-usr-local-include
#
# Install dependencies for pymumble.
#
# Set up a mumber server. For testing purpose, you can use https://guildbit.com/
# to spin up a free server. Hard code the server details in this file.
#
# run `python3 ./listen_n_talk.py`. Now an audio-only mumble client is connected
# to the server.
#
# To test its functionality, in a separate device, use some official mumble
# client (https://www.mumble.com/mumble-download.php) to verbally communicate
# with this audio-only client.
#
# Works on MacOS. Does NOT work on RPi 3B+ (I cannot figure out why. Help will
# be much appreciated)

import pymumble_py3 as pymumble_py3
from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
import pyaudio

# Connection details for mumble server. Hardcoded for now, will have to be
# command line arguments eventually
pwd = ""  # password
server = "127.0.0.1"  # server address
nick = "audio-only_client"
port = 64738  # port number


# pyaudio set up
CHUNK = 1024
FORMAT = pyaudio.paInt16  # pymumble soundchunk.pcm is 16 bits
CHANNELS = 1
RATE = 48000  # pymumble soundchunk.pcm is 48000Hz


p = pyaudio.PyAudio()
stream_listen = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                #input=True,  # enable both talk
                output=True,  # and listen
                frames_per_buffer=CHUNK)

stream_talk = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,  # enable both talk
                #output=True,  # and listen
                frames_per_buffer=CHUNK)



# mumble client set up
def sound_received_handler(user, soundchunk):
    """ play sound received from mumble server upon its arrival """
    stream_listen.write(soundchunk.pcm)


# Spin up a client and connect to mumble server
mumble = pymumble_py3.Mumble(server, nick, password=pwd, port=port)

# set up callback called when PCS event occurs
mumble.callbacks.set_callback(PCS, sound_received_handler)
mumble.set_receive_sound(1)  # Enable receiving sound from mumble server
mumble.start()
mumble.is_ready()  # Wait for client is ready


# constant capturing sound and sending it to mumble server
while True:
    data = stream_talk.read(CHUNK)
    mumble.sound_output.add_sound(data)

# close the stream and pyaudio instance
stream_talk.stop_stream()
stream_talk.close()
stream_listen.stop_stream()
stream_listen.close()
p.terminate()
@azlux
Copy link
Owner

azlux commented Apr 17, 2021

Can I put this script into the example folder of the lib ?

@l33tlinuxh4x0r
Copy link
Author

Yeah feel free... I posted it for you to update the script... Also I haven't tested it since my first post so you might want to test it again before adding it just to be sure that it works with the latest patches.

TLDR: Yes.

@piezza
Copy link

piezza commented Apr 18, 2022

Thanks, this piece of code came very handy for me. But I had to add exception_on_overflow=False to the read call:

data = stream_talk.read(CHUNK, exception_on_overflow=False)

Else the script did not run long on my RPi4.

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

3 participants