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 on README doesn't work #8

Closed
abhinavkulkarni opened this issue Oct 21, 2021 · 11 comments
Closed

Example on README doesn't work #8

abhinavkulkarni opened this issue Oct 21, 2021 · 11 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@abhinavkulkarni
Copy link

Hi,

The following example on top level README doesn't work:

from sources import MicrophoneAudioSource
from functional import FrameWiseModel, ChunkWiseModel, OverlappedSpeechPenalty, EmbeddingNormalization

mic = MicrophoneAudioSource(sample_rate=16000)

# Initialize independent modules
segmentation = FrameWiseModel("pyannote/segmentation")
embedding = ChunkWiseModel("pyannote/embedding")
osp = OverlappedSpeechPenalty(gamma=3, beta=10)
normalization = EmbeddingNormalization(norm=1)

# Branch the microphone stream to calculate segmentation
segmentation_stream = mic.stream.pipe(ops.map(segmentation))
# Join audio and segmentation stream to calculate speaker embeddings
embedding_stream = rx.zip(mic.stream, segmentation_stream).pipe(
    ops.starmap(lambda wave, seg: (wave, osp(seg))),
    ops.starmap(embedding),
    ops.map(normalization)
)

embedding_stream.suscribe(on_next=lambda emb: print(emb.shape))

mic.read()

First of all there is a type in declaring variable ops (it's been declared as osp).

Secondly, in line segmentation_stream = mic.stream.pipe(ops.map(segmentation)), there is no method named map in variable ops.

Thanks!

@KannebTo
Copy link

I came accross the same problem. ops is not osp. It is rx.operators. Here are the missing imports:

import rx
import rx.operators as ops

And there is a typo: suscribe should be subscribe.

@juanmc2005 juanmc2005 added the documentation Improvements or additions to documentation label Oct 22, 2021
@abhinavkulkarni
Copy link
Author

Hey @KannebTo:

Thanks. I renamed osp go ops. However, the other error with related there being no method named map in variable ops still persists.

@juanmc2005
Copy link
Owner

Hello, thank you for reporting these typos.
As mentioned by @KannebTo, ops references rx.operators and it's indeed subscribe.

As for the map method error, I'll try to reproduce it and get back to you.

@KannebTo
Copy link

Hey @abhinavkulkarni , just leave osp and ops as in the original code and add the imports on the top.

@abhinavkulkarni
Copy link
Author

abhinavkulkarni commented Oct 22, 2021

Hey @KannebTo,

Here's the error I get after renaming osp to ops and adding the import statements at the top:

>>> import rx
>>> import rx.operators as ops
>>> from sources import MicrophoneAudioSource

/home/user/miniconda3/envs/diarization/lib/python3.8/site-packages/torchaudio/backend/utils.py:46: UserWarning: "torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE" flag is deprecated and will be removed in 0.9.0. Please remove the use of flag.
  warnings.warn(
>>> from functional import FrameWiseModel, ChunkWiseModel, OverlappedSpeechPenalty, EmbeddingNormalization
>>> 
>>> mic = MicrophoneAudioSource(sample_rate=16000)
>>> 
>>> # Initialize independent modules
... segmentation = FrameWiseModel("pyannote/segmentation")
>>> embedding = ChunkWiseModel("pyannote/embedding")
>>> ops = OverlappedSpeechPenalty(gamma=3, beta=10)
>>> normalization = EmbeddingNormalization(norm=1)
>>> 
>>> # Branch the microphone stream to calculate segmentation
... segmentation_stream = mic.stream.pipe(ops.map(segmentation))
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'OverlappedSpeechPenalty' object has no attribute 'map'
>>> # Join audio and segmentation stream to calculate speaker embeddings
... embedding_stream = rx.zip(mic.stream, segmentation_stream).pipe(
...     ops.starmap(lambda wave, seg: (wave, osp(seg))),
...     ops.starmap(embedding),
...     ops.map(normalization)
... )
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
NameError: name 'segmentation_stream' is not defined
>>> 
>>> embedding_stream.suscribe(on_next=lambda emb: print(emb.shape))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'embedding_stream' is not defined
>>> 
>>> mic.read()

I am running this from the src directory.

@KannebTo
Copy link

KannebTo commented Oct 22, 2021

ops = OverlappedSpeechPenalty(gamma=3, beta=10) must be osp as in the original

@KannebTo
Copy link

from sources import MicrophoneAudioSource
from functional import FrameWiseModel, ChunkWiseModel, OverlappedSpeechPenalty, EmbeddingNormalization
import rx
import rx.operators as ops

mic = MicrophoneAudioSource(sample_rate=16000)

# Initialize independent modules
segmentation = FrameWiseModel("pyannote/segmentation")
embedding = ChunkWiseModel("pyannote/embedding")
osp = OverlappedSpeechPenalty(gamma=3, beta=10)
normalization = EmbeddingNormalization(norm=1)

# Branch the microphone stream to calculate segmentation
segmentation_stream = mic.stream.pipe(ops.map(segmentation))
# Join audio and segmentation stream to calculate speaker embeddings
embedding_stream = rx.zip(mic.stream, segmentation_stream).pipe(
    ops.starmap(lambda wave, seg: (wave, osp(seg))),
    ops.starmap(embedding),
    ops.map(normalization)
)

embedding_stream.subscribe(on_next=lambda emb: print(emb.shape))

mic.read()

@juanmc2005
Copy link
Owner

This should be fixed now.
Please let me know if it works from your end.

@juanmc2005 juanmc2005 added the bug Something isn't working label Oct 22, 2021
@abhinavkulkarni
Copy link
Author

Thanks, it works!

@KannebTo
Copy link

Thanks! Yes it works with the regularize_stream().

But i have another issue with the audio access, probably due to my audio setup:

>>> mic.read()
torch.Size([4, 512])
python: src/hostapi/alsa/pa_linux_alsa.c:3641: PaAlsaStreamComponent_BeginPolling: Assertion `ret == self->nfds' failed.
Aborted (core dumped)

This is strange because I'm running this in a Docker container and I also use the sounddevice library without problems in another project in the same container.

@juanmc2005
Copy link
Owner

@KannebTo would you mind creating a separate issue for this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants