How to emit sound??

Please post any questions about developing your plugin here. Please use the search function before posting!
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

How to emit sound??

Postby 8guawong » Fri Sep 26, 2014 4:37 pm

Syntax: Select all

# SourcePython
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from engines.sound import Sound, VOL_NORM, SOUND_FROM_WORLD

from filters.recipients import RecipientFilter
from listeners import LevelInit

cheer = Sound((), SOUND_FROM_WORLD, "cheer/cheer_1.wav", download=True, volume=VOL_NORM)


def load():
cheer.precache()

@LevelInit
def map_start(mapname):
cheer.precache()

@Event
def player_jump(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
cheer.play(RecipientFilter(player.index))


script loads and downloaded sound file but no sound played

tested game: CSGO
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Sep 26, 2014 4:47 pm

You don't need to precache the sound. Our Sound class will do that for you.

Are there any errors in your client console?
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Fri Sep 26, 2014 4:52 pm

Ayuto wrote:You don't need to precache the sound. Our Sound class will do that for you.

Are there any errors in your client console?


no no errors
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Sep 27, 2014 3:10 am

I don't have time to test this right now, but i do have a couple pointers.

First, we changed the default volume to be VOL_NORM, so there is no need for you to import it and set that value on instantiation:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L104


Also, there is no need to import RecipientFilter, as the API automatically uses that with either the given recipients on play or the instance's recipients:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L139

As Ayuto mentioned, the class already precaches the sound prior to playing:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L141
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Sat Sep 27, 2014 4:06 am

satoon101 wrote:I don't have time to test this right now, but i do have a couple pointers.

First, we changed the default volume to be VOL_NORM, so there is no need for you to import it and set that value on instantiation:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L104


Also, there is no need to import RecipientFilter, as the API automatically uses that with either the given recipients on play or the instance's recipients:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L139

As Ayuto mentioned, the class already precaches the sound prior to playing:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/engines/sound.py#L141


Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from engines.sound import Sound, VOL_NORM, SOUND_FROM_WORLD

cheer = Sound((), SOUND_FROM_WORLD, "cheer/cheer_1.wav", download=True)

@Event
def player_jump(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
cheer.play()


still nothing :frown:
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Sep 27, 2014 4:26 am

This code works for me.

Code: Select all

Failed to load sound "cheer\cheer_1.wav", file probably missing from disk/repository
Failed to load sound "cheer\cheer_1.wav", file probably missing from disk/repository
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Sat Sep 27, 2014 5:09 am

L'In20Cible wrote:This code works for me.

Code: Select all

Failed to load sound "cheer\cheer_1.wav", file probably missing from disk/repository
Failed to load sound "cheer\cheer_1.wav", file probably missing from disk/repository


Code: Select all

[Sound] S_StartSound(): Failed to load sound 'cheer\blah.wav'. File is missing from disk/repository.



well i get that msg client side as well if i put a non existent sound file in the code :cool:
qazuar
Junior Member
Posts: 16
Joined: Fri Jun 20, 2014 9:05 am

Postby qazuar » Sun Sep 28, 2014 11:42 am

My csgo server still crashes whenever i play a sound (with and without the soundclass), so i would like to know how you guys can make it work on csgo.
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Postby Hedgehog » Sun Sep 28, 2014 12:14 pm

Some time ago when engine_sound.emit_sound was crashing server in CS:S as temporary fix I used this (with manual sound precache in load and level init listener):

Syntax: Select all

EngineServer.client_command(edict, 'play some/cool/sound.wav')

I'm not sure that it will work in CS:GO, but you should try...
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Wed Oct 01, 2014 5:05 pm

Hedgehog wrote:Some time ago when engine_sound.emit_sound was crashing server in CS:S as temporary fix I used this (with manual sound precache in load and level init listener):

Syntax: Select all

EngineServer.client_command(edict, 'play some/cool/sound.wav')

I'm not sure that it will work in CS:GO, but you should try...


how do you precache sound?? i'm trying to use your example but donno how to precache sound

Syntax: Select all

from events import Event
from players.helpers import edict_from_userid
import engines
from stringtables.downloads import Downloadables
from engines.server import engine_server

dl = Downloadables()
dl.add("sound/cheer/cheer_1.wav")

@Event
def player_jump(game_event):
userid = game_event.get_int('userid')
edict = edict_from_userid(userid)
engine_sound.precache_sound("sound/cheer/cheer_1.wav")
engine_server.client_command(edict, 'play sound/cheer/cheer_1.wav')


would be really awesome if some1 can provide working code for emiting sound for csgo... REALLY want it!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Oct 01, 2014 9:51 pm

Did we ever fix sending sounds for CS:GO? The announcement thread shows that it should crash on that engine, and I don't believe we ever fixed that. I am surprised your's is not crashing, actually.
http://www.sourcepython.com/showthread.php?551-New-Sound-class!!
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Wed Oct 01, 2014 11:09 pm

well the code i posted don't work :eek:
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Oct 02, 2014 3:20 am

Could you add a debug message to show whether or not that event is even working?

Also, your precache and client_command lines I don't believe should be including the sound/ directory. The Downloadables does require the sound/ prefix, as you already have it.
Image
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Postby Hedgehog » Thu Oct 02, 2014 4:38 am

Something like this:

Syntax: Select all

from engines.server import engine_server
from engines.sound import Sound, VOL_NORM, SOUND_FROM_WORLD
from events import Event
from listeners import LevelInit


my_sound = Sound((), SOUND_FROM_WORLD, "cheer/cheer_1.wav", download=True, volume=VOL_NORM)


def load():
my_sound.precache()
# engine_sound.precache_sound("sound/cheer/cheer_1.wav")


@LevelInit
def on_level_init(mapname):
my_sound.precache()
# engine_sound.precache_sound("sound/cheer/cheer_1.wav")


@Event
def player_jump(game_event):
userid = game_event.get_int('userid')
edict = edict_from_userid(userid)
engine_server.client_command(edict, 'play sound/cheer/cheer_1.wav')

I used Sound class because I strongly believe that one day S.P team will fix it :) But if you don't like it just use engine_sound.precache_sound.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Thu Oct 02, 2014 8:09 am

satoon101 wrote:Could you add a debug message to show whether or not that event is even working?

Also, your precache and client_command lines I don't believe should be including the sound/ directory. The Downloadables does require the sound/ prefix, as you already have it.


Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/events/listener.py", line 90, in fire_game_event
    callback(game_event)
  File "../addons/source-python/plugins/test/test.py", line 31, in player_jump
    engine_sound.precache_sound("sound/cheer/cheer_1.wav")

NameError: name 'engine_sound' is not defined


Hedgehog wrote:Something like this:

Syntax: Select all

from engines.server import engine_server
from engines.sound import Sound, VOL_NORM, SOUND_FROM_WORLD
from events import Event
from listeners import LevelInit


my_sound = Sound((), SOUND_FROM_WORLD, "cheer/cheer_1.wav", download=True, volume=VOL_NORM)


def load():
my_sound.precache()
# engine_sound.precache_sound("sound/cheer/cheer_1.wav")


@LevelInit
def on_level_init(mapname):
my_sound.precache()
# engine_sound.precache_sound("sound/cheer/cheer_1.wav")


@Event
def player_jump(game_event):
userid = game_event.get_int('userid')
edict = edict_from_userid(userid)
engine_server.client_command(edict, 'play sound/cheer/cheer_1.wav')

I used Sound class because I strongly believe that one day S.P team will fix it :) But if you don't like it just use engine_sound.precache_sound.


sorry not sure if theres any difference from the code i posted other than using the sound class and precaching @ map start / plugin-load??
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Postby Hedgehog » Thu Oct 02, 2014 8:48 am

Sorry, I forgot to import it...

Syntax: Select all

from engines.sound import engine_sound


And as I said earlier
Hedgehog wrote:I'm not sure that it will work in CS:GO, but you should try...
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Thu Oct 02, 2014 3:01 pm

Hedgehog wrote:Sorry, I forgot to import it...
[python]from engines.sound import engine_sound[/python]

And as I said earlier
Hedgehog wrote:I'm not sure that it will work in CS:GO, but you should try...


ok i'll report back after i tried it
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Fri Oct 03, 2014 11:49 am

ok this works in csgo (linux)

Syntax: Select all

from events import Event
from players.helpers import edict_from_userid
from stringtables.downloads import Downloadables
from engines.server import engine_server

dl = Downloadables()
dl.add("sound/custom/sound.mp3")

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
edict = edict_from_userid(userid)
engine_server.client_command(edict, 'play *custom/sound.mp3')


you don't have to precache and ONLY works with MP3
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Oct 05, 2014 6:32 am

Alright so, I just spent few hours trying all and everything and found out that any sound which is not in the ../sound/music/ folder is just ignored by the clients...

For those interested, here is my test script.
Attachments
BoomHeadshot.zip
(25.44 KiB) Downloaded 470 times
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Oct 05, 2014 12:18 pm

That seems very odd... I wonder why Valve did that?
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 124 guests