Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriacai01 committed Sep 13, 2024
1 parent 38abc09 commit d67bb9c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ abstract class AudioInput(name: String) : Component(SUBTYPE, named(name)) {
/**
* Stream audio samples from the audio input of the underlying robot
*/
abstract fun stream() : AudioStream
abstract fun stream(): AudioStream

/**
* Get the properties of the audio input of the underlying robot
*/
abstract fun getProperties() : Properties
abstract fun getProperties(): Properties

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AudioInputRPCClient(name: String, channel: Channel) : AudioInput(name) {
}

override fun stream(): AudioStream {
val request = Audioinput.ChunksRequest.newBuilder().setName(this.name.name).setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).build()
val request = Audioinput.ChunksRequest.newBuilder().setName(this.name.name)
.setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).build()
val response = this.client.chunks(request)
return response
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.viam.sdk.core.component.audioinput

import com.google.api.HttpBody
import com.viam.common.v1.Common.*
import com.viam.component.audioinput.v1.AudioInputServiceGrpc
import com.viam.component.audioinput.v1.Audioinput
Expand All @@ -8,7 +9,8 @@ import com.viam.sdk.core.resource.ResourceRPCService
import io.grpc.stub.StreamObserver
import java.util.*

internal class AudioInputRPCService(private val manager: ResourceManager) : AudioInputServiceGrpc.AudioInputServiceImplBase(),
internal class AudioInputRPCService(private val manager: ResourceManager) :
AudioInputServiceGrpc.AudioInputServiceImplBase(),
ResourceRPCService<AudioInput> {

override fun chunks(
Expand All @@ -17,7 +19,7 @@ internal class AudioInputRPCService(private val manager: ResourceManager) : Audi
) {
val audioInput = getResource(AudioInput.named(request.name))
val response = audioInput.stream()
for(chunk in response){
for (chunk in response) {
responseObserver.onNext(chunk)
}
responseObserver.onCompleted()
Expand All @@ -32,6 +34,11 @@ internal class AudioInputRPCService(private val manager: ResourceManager) : Audi
responseObserver.onNext(result)
responseObserver.onCompleted()
}

override fun record(request: Audioinput.RecordRequest?, responseObserver: StreamObserver<HttpBody>?) {
throw UnsupportedOperationException()
}

override fun doCommand(
request: DoCommandRequest, responseObserver: StreamObserver<DoCommandResponse>
) {
Expand All @@ -49,13 +56,13 @@ internal class AudioInputRPCService(private val manager: ResourceManager) : Audi
responseObserver.onNext(GetGeometriesResponse.newBuilder().addAllGeometries(result).build())
responseObserver.onCompleted()
}

override fun getResourceClass(): Class<AudioInput> {
return AudioInput::class.java
}

override fun getManager(): ResourceManager {
return this.manager
return this.manager
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ class AudioInputRPCClientTest {
}

@Test
fun stream(){
fun stream() {

fun createChunks(): MutableList<ChunksResponse> {
val chunks: MutableList<ChunksResponse> = mutableListOf()
for (i in 0..5) {
val chunk = Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2).build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4).setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L).build()
val chunk =
Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2)
.build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4)
.setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L)
.build()
val audioChunk = ChunksResponse.newBuilder().setChunk(chunk).setInfo(info).build()
chunks.add(audioChunk)
}
Expand All @@ -71,8 +75,11 @@ class AudioInputRPCClientTest {
}

@Test
fun getProperties(){
val properties = PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2).setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true).build()
fun getProperties() {
val properties =
PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2)
.setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true)
.build()
`when`(audioInput.getProperties()).thenReturn(properties)
val response = client.getProperties()
verify(audioInput).getProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ class AudioInputRPCServiceTest {
}

@Test
fun chunks(){
fun chunks() {
fun createChunks(): MutableList<ChunksResponse> {
val chunks: MutableList<ChunksResponse> = mutableListOf()
for (i in 0..5) {
val chunk = Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2).build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4).setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L).build()
val chunk =
Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2)
.build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4)
.setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L)
.build()
val audioChunk = ChunksResponse.newBuilder().setChunk(chunk).setInfo(info).build()
val time = Instant.now().epochSecond
chunks.add(audioChunk)
Expand All @@ -79,14 +83,18 @@ class AudioInputRPCServiceTest {
}

@Test
fun getProperties(){
val properties = PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2).setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true).build()
fun getProperties() {
val properties =
PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2)
.setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true)
.build()
`when`(audioInput.getProperties()).thenReturn(properties)
val request = Audioinput.PropertiesRequest.newBuilder().setName(audioInput.name.name).build()
val response = client.properties(request)
verify(audioInput).getProperties()
assertEquals(properties, response)
}

@Test
fun doCommand() {
val command =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.google.protobuf.Duration
import com.viam.component.audioinput.v1.Audioinput
import com.viam.component.audioinput.v1.Audioinput.ChunksResponse
import com.viam.component.audioinput.v1.Audioinput.PropertiesResponse
import com.viam.sdk.core.component.audioinput.AudioInput
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -21,13 +20,17 @@ class AudioInputTest {
}

@Test
fun stream(){
fun stream() {

fun createChunks(): MutableList<ChunksResponse> {
val chunks: MutableList<ChunksResponse> = mutableListOf()
for (i in 0..5) {
val chunk = Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2).build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4).setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L).build()
val chunk =
Audioinput.AudioChunk.newBuilder().setData(ByteString.copyFromUtf8(i.toString())).setLength(2)
.build()
val info = Audioinput.AudioChunkInfo.newBuilder().setChannels(4)
.setSampleFormat(Audioinput.SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED).setSamplingRate(1000L)
.build()
val audioChunk = ChunksResponse.newBuilder().setChunk(chunk).setInfo(info).build()
chunks.add(audioChunk)
}
Expand All @@ -46,12 +49,15 @@ class AudioInputTest {

@Test
fun getProperties() {
val properties = PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2).setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true).build()
val properties =
PropertiesResponse.newBuilder().setLatency(Duration.newBuilder().setSeconds(3000L).build()).setSampleRate(2)
.setSampleSize(3).setIsFloat(true).setChannelCount(4).setIsBigEndian(true).setIsInterleaved(true)
.build()
`when`(audioinput.getProperties()).thenReturn(properties)
val response = audioinput.getProperties()
verify(audioinput).getProperties()
assertEquals(properties, response)

}

}

0 comments on commit d67bb9c

Please sign in to comment.