Skip to content

Commit

Permalink
DEVEXP-373: voice textToSpeech snippet (#1)
Browse files Browse the repository at this point in the history
* TextToSppech snippet
* 'numbers.available.list' snippet
  • Loading branch information
JPPortier authored May 28, 2024
1 parent 9b40b6d commit 2781c4f
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/compilation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Compilation

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Building
run: |
./compile.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# sinch-sdk-java-snippets
Sinch Java SDK Code Snippets Repository

This repository contains code snippets related to [Sinch JAVA SDK](https://github.com/sinch/sinch-sdk-java)
4 changes: 4 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

(cd snippets && mvn clean spotless:apply compile)

32 changes: 32 additions & 0 deletions snippets/numbers/available/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package numbers;

import com.sinch.sdk.domains.numbers.*;
import com.sinch.sdk.domains.numbers.models.NumberType;
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberListAllRequestParameters;
import java.util.logging.Logger;

public class List {

private static final Logger LOGGER = Logger.getLogger(List.class.getName());

public void list(NumbersService numbersService) {

var availableNumbersService = numbersService.available();

var regionCode = "US";
var type = NumberType.LOCAL;

var parameters =
AvailableNumberListAllRequestParameters.builder()
.setRegionCode(regionCode)
.setType(type)
.build();

var response = availableNumbersService.list(parameters);

response.iterator()
.forEachRemaining(
number ->
LOGGER.info(String.format("Available number details: %s", number)));
}
}
94 changes: 94 additions & 0 deletions snippets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.sinch.sdk.archetypes</groupId>
<artifactId>sinch-java-sdk-client-snippets</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Sinch Java SDK Client Snippets</name>

<properties>
<sinch.sdk.java.version>[1.0.0,)</sinch.sdk.java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.version>3.8.0</maven.compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>.</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<!-- code format -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>

<configuration>

<java>
<includes>
<include>**/*.java</include>
</includes>

<googleJavaFormat>
<version>1.22.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
<endWithNewline />
<removeUnusedImports />
<indent>
<spaces>true</spaces>
<spacesPerTab>2</spacesPerTab>
</indent>
<trimTrailingWhitespace />
</java>

</configuration>

<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.sinch.sdk</groupId>
<artifactId>sinch-sdk-java</artifactId>
<version>${sinch.sdk.java.version}</version>
</dependency>

</dependencies>

</project>
26 changes: 26 additions & 0 deletions snippets/voice/callouts/TextToSpeech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package voice.callouts;

import com.sinch.sdk.domains.voice.*;
import com.sinch.sdk.domains.voice.models.DestinationNumber;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersTTS;

public class TextToSpeech {

public String call(VoiceService voiceService, String phoneNumber) {

var calloutsService = voiceService.callouts();

var destination = DestinationNumber.valueOf(phoneNumber);
var message =
"Hello, this is a call from Sinch. Congratulations! You made your first call.";

var parameters =
CalloutRequestParametersTTS.builder()
.setDestination(destination)
.setText(message)
.build();

var callId = calloutsService.textToSpeech(parameters);
return callId;
}
}

0 comments on commit 2781c4f

Please sign in to comment.