Page 1 of 2

How to emit sound??

Posted: Fri Sep 26, 2014 4:37 pm
by 8guawong

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

Posted: Fri Sep 26, 2014 4:47 pm
by Ayuto
You don't need to precache the sound. Our Sound class will do that for you.

Are there any errors in your client console?

Posted: Fri Sep 26, 2014 4:52 pm
by 8guawong
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

Posted: Sat Sep 27, 2014 3:10 am
by satoon101
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

Posted: Sat Sep 27, 2014 4:06 am
by 8guawong
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:

Posted: Sat Sep 27, 2014 4:26 am
by L'In20Cible
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

Posted: Sat Sep 27, 2014 5:09 am
by 8guawong
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:

Posted: Sun Sep 28, 2014 11:42 am
by qazuar
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.

Posted: Sun Sep 28, 2014 12:14 pm
by Hedgehog
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...

Posted: Wed Oct 01, 2014 5:05 pm
by 8guawong
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!

Posted: Wed Oct 01, 2014 9:51 pm
by satoon101
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!!

Posted: Wed Oct 01, 2014 11:09 pm
by 8guawong
well the code i posted don't work :eek:

Posted: Thu Oct 02, 2014 3:20 am
by satoon101
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.

Posted: Thu Oct 02, 2014 4:38 am
by Hedgehog
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.

Posted: Thu Oct 02, 2014 8:09 am
by 8guawong
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??

Posted: Thu Oct 02, 2014 8:48 am
by Hedgehog
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...

Posted: Thu Oct 02, 2014 3:01 pm
by 8guawong
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

Posted: Fri Oct 03, 2014 11:49 am
by 8guawong
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

Posted: Sun Oct 05, 2014 6:32 am
by L'In20Cible
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.

Posted: Sun Oct 05, 2014 12:18 pm
by satoon101
That seems very odd... I wonder why Valve did that?